0

My ultimate goal is to take a string like "a.b;c.d;e.f.g" and perform an operation on each token delimited by ';', which includes a for loop that separately processes each subtoken delimited by '.'

I have split the origin input like so:

FOR %%i IN (%input%) DO (
  ECHO %%i
)

This seems to work but now I can't use the :.=; syntax to get %%i ready to be split again. I have tried SET iVar=%%i to then be able to use this syntax but the SET doesn't work, iVar remains empty. I do have EnableDelayedExpansion set.

To clarify, if loop variables were just normal variables in batch my final script would be something like this:

FOR %i% IN (%input%) DO (
  ECHO %i%
  FOR %j% in (!i:.=;!) DO (
    ECHO %j%
  )
)

and the output would be

a.b
a
b
c.d
c
d
e.f.g
e
f
g

1 Answer 1

1

Try like this :

@echo off
setlocal enabledelayedexpansion
set "$input=a.b;c.d;e.f.g"
for %%a in (%$input%) do (
   echo %%a
   set "$int=%%a"
   set "$int=!$int:.= !"
   for %%b in (!$int!) do echo %%b)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I think I actually was trying this solution earlier but thought set $int=%%a wasn't working because I was using % instead of ! later on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.