Page 1 of 1

For loop value with spaces

Posted: 16 Sep 2024 17:20
by SIMMS7400
Hi All -

I am reaching out to see if there is a cleaner way to prepare a passed value for use in a for loop. For instance, I'm passing this value to a function :
CALL :TEST "ACR_US Bank_Regions,AR_EFT"
However, I need to iterate over both values, but space is considered a delimiter. So I am doing the following :

Code: Select all

SET "AUTOMATCH=!AUTOMATCH:, =,!"   & REM Ensure no spaces after comma
SET "AUTOMATCH=!AUTOMATCH: =@!"    & REM Temporarily replace spaces with @
SET AUTOMATCH="!AUTOMATCH:,=","!"  & REM Wrap double quotes around each DLR
SET "AUTOMATCH=!AUTOMATCH:@= !"    & REM Remove @ and replace with spac
Then using it like this :

Code: Select all

FOR %%A IN (!AUTOMATCH!,= !) DO ECHO %%A
Is there a cleaner way?

Re: For loop value with spaces

Posted: 17 Sep 2024 03:36
by SIMMS7400
I looks like I can just do this, so simple :

Code: Select all

SET "AUTOMATCH=%~1"

Code: Select all

FOR %%A IN ("%AUTOMATCH:,=" "%") DO (