Page 1 of 1

For /f processing delimited string

Posted: 25 Dec 2018 07:28
by Blazer
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

Re: For /f processing delimited string

Posted: 25 Dec 2018 09:24
by IcarusLives
You want something like this...?

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
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

Re: For /f processing delimited string

Posted: 26 Dec 2018 07:23
by Blazer
@IcarusLives

Thanks for your help. 8)

Re: For /f processing delimited string

Posted: 30 Dec 2018 09:34
by Aacini
If you have the target string in a variable, and the substrings have not ? * wild-card characters, then you may use this simple trick:

Code: Select all

set "var=123?456?789"
for %A in ("%var:?=" "%") do echo %~A
Antonio

Re: For /f processing delimited string

Posted: 02 Jan 2019 05:02
by Blazer
@Aacini

Thank you, your batch-fu is strong 8)