I have the following string:
AAA:BBB, CCC:DDD, EEE:FFF
I need to extract BBB, DDD and FFF into separate variables, because I need to run another script once for each of these variable, with the variables as parameters. In this example I would need to run:
script.cmd BBB
script.cmd DDD
script.cmd FFF
The string could be just "AAA:BBB" or it could have 10 of these formats, up to "YYY:ZZZ". My train of thoughts is to make an array out of the string. First I will remove all eventual spaces in the initial string, then separate the elements on comas. So the result would be:
Array[0]=AAA:BBB
Array[1]=CCC:DDD
.......
Array[n]=YYY:ZZZ
After that, I can take each element and try to delete "*:", and be left with :
Array[0]=BBB
Array[1]=DDD
.......
Array[n]=ZZZ
And then I can use these as parameters. I did the following:
rem -- set string
set STRING=AAA:BBB, CCC:DDD, EEE:FFF
rem -- trim eventual spaces in STRING
set STRING=%STRING: =%
rem -- replaces comas with spaces to be able to create array
set STRING=%STRING:,= %
setlocal ENABLEDELAYEDEXPANSION
rem -- split string into array
set index=0
for %%A in (%STRING%) do (
set Array[!index!] = %%A
set /a index += 1
)
Splitting works great. But this is where I got stuck. I tried for the past hours to take each element of the array and remove all characters until colon, including colon. Not sure what I'm doing wrong, the output is just weird. I tried using the same for, used for splitting the string, to also run the scripts with parameters. I tried using another for after the splitting is complete. Nothing works.
Seems like the command:
set string=%string:*:=%
.. does not work for some reason for each element of the array. Output is weird, something like "stringn=%=%" . And I don't understand why. Same command works great for other variables that are not elements of the array.
Anyone have any suggestions? Much appreciated.