Str.exe string count, display, and compare makes batch string handling easier.

Jerold Schulman

October 29, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Download Bill Stewart's freeware Batch Script Tools 2.5 and extract the new Str.exe file to a folder that is in your PATH.

When you type str /?, you receive:

Str 2.5 - (C) 2004-2006 by Bill Stewart ([email protected])Usage: str [-c | -l | -u] string   or: str [-i] -p string1 string2-c  Echoes the number of character in string (count).-l  Echoes the specified string in lowercase.-u  Echoes the specified string in uppercase.-p  Echoes the starting position of string2 in string1 (-1 = not found).-i  Specifies a case-insensitive comparison (must appear before -p).

Sample Usage

When you type str -p ABCDEFGHIJKLMNOP IJK in a CMD.EXE window, Str.exe returns 8, indicating that IJK starts at the 9th byte. Counting starts at 0.

To use this in a batch script:

......set BigString=ABCDEFGHIJKLMNOPset ArgString=IJKfor /f "Tokens=*" %%a in ('str -p %BigString% %ArgString%') do ( set /a pos=%%a)if %pos% LSS 0 @echo %ArgString% was not found in %BigString%.&goto :EOF@echo %ArgString% is at position %pos% in %BigString%, counting from 0.......


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like