JSI Tip 9576. How do I process each character in a string?

I have scripted EachChar.bat to process each character in a string.

The syntax for using EachChar.bat is:

for /f "Tokens=*" %%a in ('EachChar string') do (
::Do something with the %%a character, like:
 @echo %%a
Where string is the string you wish to parse.

EachChar.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: EachChar String&goto :EOF
set string=%1
if exist "%TEMP%\EachChar.vbs" goto parse
@echo Set objshell = CreateObject("WScript.Shell")>"%TEMP%\EachChar.vbs"
@echo Set objArgs = WScript.Arguments>>"%TEMP%\EachChar.vbs"
@echo For n = 1 To Len(objArgs(0))>>"%TEMP%\EachChar.vbs"
@echo.   WScript.Echo Mid(objArgs(0), n, 1)>>"%TEMP%\EachChar.vbs"
@echo Next>>"%TEMP%\EachChar.vbs"
cscript //nologo "%TEMP%\EachChar.vbs" %string%

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.