Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 :


@echo off

set params=param1,param2,param3

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


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

Your Answer


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.