Page 1 of 1

String split with separaotr

Posted: 11 Jun 2010 01:43
by kameha
hi there !

I've got the following script:

Code: Select all

SET BASES_NAMES=Base1,Base2

FOR /F "tokens=1 delims=," %%a IN ("%BASES_BTT%") DO (
   ECHO Valeur: %%a
)


I would like to produce the following output:

Valeur: Base1
Valeur: Base2

But can only have the first line... why ?

please help !

Re: String split with separaotr

Posted: 11 Jun 2010 05:55
by Barty
You need to change tokens to 1-2
You need to write the right var
You need to echo %%b

SET BASES_NAMES=Base1,Base2

FOR /F "tokens=1-2 delims=," %%a IN ("%BASES_NAMES%") DO (
ECHO Valeur: %%a
ECHO Valeur: %%b
)


%%a = Base1
%%b = Base2

Re: String split with separaotr

Posted: 11 Jun 2010 05:58
by aGerman
Try this

Code: Select all

SET BASES_NAMES=Base1,Base2

FOR /F "tokens=1,2 delims=," %%a IN ("%BASES_NAMES%") DO (
   ECHO Valeur: %%a
   ECHO Valeur: %%b
)


[edit]
Yeah, you're right. The variable name is also wrong.
One more explanation:
- tokens=1,2 is for "first(%%a) and second(%%b) token"
- tokens=1-2 is for "first(%%a) until second(%%b) token"
- tokens=1* is for "first(%%a) token and the whole rest(%%b)"
All these possibilities will work for your example.
[/edit]


Regards
aGerman

Re: String split with separaotr

Posted: 13 Jun 2010 23:07
by amel27
enumerate all instances:

Code: Select all

SET BASES_NAMES=Base1,Base2

FOR %%a IN (%BASES_NAMES%) DO (
   ECHO Valeur: %%a
)