3

I have a little question.
ı want string split with cmd.
Example :

emre;bahadir;131213034;computer

i want to

var1=emre 
var2=bahadir 
var3=131213034 
var4=computer 

please help me ! :)

Atri
  • 5,511
  • 5
  • 30
  • 40
Emre BAHADIR
  • 31
  • 1
  • 3
  • Do you want to do this in windows command prompt? Is it given that there won't be more than 4 tokens? If not, it should be stored in an array. – Atri Nov 11 '15 at 23:27
  • 3
    This might help you: http://stackoverflow.com/questions/1707058/how-to-split-a-string-in-a-windows-batch-file – Atri Nov 11 '15 at 23:30
  • Did ashutosh's link not help you? Where did you get stuck? – Josef Engelfrost Nov 11 '15 at 23:37
  • This should be closed, there is no evidence of self-starting and it has been answered previously. – Mathemats Nov 12 '15 at 00:06

2 Answers2

2

Just use a regular FOR loop

@Echo OFF 

Set "str=emre;bahadir;131213034;computer"

For %%_ In (%str%) DO (
    echo %%_
)

Pause&Exit /B 0
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
0

basically the same as ElektroStudios' answer, but expanded with a counter to set the variables:

setlocal enabledelayedexpansion
set "str=emre;bahadir;131213034;computer"
set x=0
For %%a In (%str%) DO (
  set /a x+=1
  set "var!x!=%%a"
)
set var
Stephan
  • 53,940
  • 10
  • 58
  • 91