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

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 ArgString=IJK
for /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.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.