AFAIK, FOR cannot iterate character by character. A possible workaround is to create a loop as follows:
@ECHO OFF :: string terminator: chose something that won't show up in the input file SET strterm=___ENDOFSTRING___ :: read first line of input file SET /P mytext=<C:\MYTEXTFILE.txt :: add string terminator to input SET tmp=%mytext%%strterm% :loop :: get first character from input SET char=%tmp:~0,1% :: remove first character from input SET tmp=%tmp:~1% :: do something with %char%, eg simply print it out ECHO char: %char% :: repeat until only the string terminator is left IF NOT "%tmp%" == "%strterm%" GOTO loop
Note. The question header says that you want to iterate over “every character in the variable string”, which assumes that the input file contains only one line, because the command (set /P MYTEXT=)<C:\MYTEXTFILE.txt will read only the first line C:\MYTEXTFILE.txt . If you want to iterate over all the lines in a file instead, the solution is a bit more complicated, and I suggest you open another question for it.
zb226 source share