Reputation: 77
So I have a list of dates which can be any amount in theory like this separated by and underscore in a string format.
I would like to split this string and use it within a for loop with further code but when echo ing only the first date is printed i.e 02/03/2020 in this case.
The code I am using is as follows:
@Echo off
Set dates=02/03/2020_03/04/202_04/04/2020
for /f "delims=_" %%b in ("%dates%") do (
Echo %%b
)
I also tried using tokens just to see what would happen and this code below printed more than one but as I don't know how many dates that isn't practical for me
for /f "tokens=1,2 delims=_" %%b in ("%dates%") do (
Echo %%b
Echo %%c
And finally I also tried using 1* in the tokens section but that just returned the string as it is without being delimited at all
Any advise for what I may be doing wrong here would be very appreciated
Upvotes: 0
Views: 3193
Reputation: 2951
In batch scripting, variables are assigned using the Set
xommand. open cmd and type set /?
Additionally, tokens / delims is unecessary. Use substring modification to replace _
with a standard delimiter.
@Set "dates=02/03/2020_03/04/2020_04/04/2020"
@For %%G in (%Dates:_= %)Do @Echo/%%G
Upvotes: 1