Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
Is there any way for a for loop to parse each word in a string one by one?
For instance,
For /F %%i in ('findstr /c:"TestString" file.txt') do echo %%i
will only echo the first word of each line. If I put in "tokens=*" then it gives me the whole line at once...I want each word in the line one at a time, and I don't want to hardcode what token number the string is at or how many words are on each line.
Thanks for any help,
-Lila

The following returns each word in a For controlled loop
For /F "tokens=*" %%I in ('FindStr /C:"TestString" File.txt') Do Call :PARSE %%I
....
....
GoTo :EOF:PARSE
If "%1"=="" GoTo :EOF
Echo %1
Shift
GoTo :PARSEWhere :EOF is the standard built in return label for XP/2k/NT batch scripts and does not need to be declared and :PARSE is an internal subroutine.

Thanks for the help! Unfortunately I guess my case isn't that simple. The line I'm actually trying to parse is from an xml file, and looks something like this:
<Product UpgradeCode="CC0107D0-E535-4D7D-9EF4-82C9F07F2AD6" Name="my installer" Id="F60BBF4F-E3D9-41E1-88CB-0798D0EC1A4E" Version="2.0.0.1" Manufacturer="my work" Language="1033">
I need to pick out the Version attribute. When I try and adapt the code, for one thing the < and > characters cause problems. When I set tokens=2* to get past the <, the only arguments that seem to be passed to :PARSE are UpgradeCode and "CC0107D0-E535-4D7D-9EF4-82C9F07F2AD6".
I was hoping there was a routine that would just loop me through every word tokenized by white space. Any ideas?

looking through, even white space wouldn't work. I've put together something with a lot of different calls and got it to work, but thanks for your help!

![]() |
Please help!
|
Intel assembler
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |