for /f "delims=?" %A in ("123?456?789") do echo %A
This runs the loop once and sets %A to 123
I want it to loop for each substring based on the delimiter so that I can run a number of commands on %A
Loop 1 %A = 123
Loop 2 %A = 456
Loop 3 %A = 789
Thank you
For /f processing delimited string
Moderator: DosItHelp
-
- Posts: 175
- Joined: 17 Jan 2016 23:55
Re: For /f processing delimited string
You want something like this...?
I couldn't manage to get commands like for and if to work in this instance.
Commands that use ( ) in their syntax seem to break even if escaping the closing ).
Hopefully this points you in the right direction
Code: Select all
@echo off & setlocal enableDelayedExpansion
for /f "tokens=1-2 delims=?" %%a in ("echo?set") do (
for /l %%c in (1,1,10) do (
%%b /a "a[%%c]=!random! %% 2"
%%a %%c = !a[%%c]!
)
)
pause & exit
Commands that use ( ) in their syntax seem to break even if escaping the closing ).
Hopefully this points you in the right direction
Re: For /f processing delimited string
@IcarusLives
Thanks for your help.
Thanks for your help.
Re: For /f processing delimited string
If you have the target string in a variable, and the substrings have not ? * wild-card characters, then you may use this simple trick:
Antonio
Code: Select all
set "var=123?456?789"
for %A in ("%var:?=" "%") do echo %~A
Re: For /f processing delimited string
@Aacini
Thank you, your batch-fu is strong
Thank you, your batch-fu is strong