Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to extract some data from input string (e.g. name1,name2,name3...), and then use all of them as a variables (e.g. var1=name1, var2=name2, varN=nameN). The number of 'names' can be different. I want to apply a set of commands for these variables in a FOR loop later in the script.

share|improve this question
    
Are the variables separated by commas in your input string? –  iglvzx May 22 '12 at 1:26
    
yes, any deliminator actually –  Anna May 22 '12 at 5:28

1 Answer 1

up vote 0 down vote accepted

You can use a "for each" loop like so:

set params=param1,param2,param3

for %%p in (%params%) do (
    :: do something with %%p
)

Aside from a comma ,, the other valid delimiters are:

  • a semicolon ;
  • an equals sign =
  • a space character
  • a tab character

Example :

Script:

@echo off

set params=param1,param2,param3

for %%p in (%params%) do (
    echo %%p
)

Output:

param1
param2
param3
share|improve this answer
    
Thank you very much! It works now!!!!! –  Anna May 22 '12 at 23:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.