Creating a string by parsing user input

February 14, 2010 at 03:27:15
Specs: Windows XP
Hello folks. In a batch file I'm building, I want to check what letters were input by the user and create a string based on that.

The batch file gives the user a menu like this:

Whose name(s) do you wish to process?

A for Aaron
B for Barry
C for Charlie
D for Danny
E for Eric

The user should be able to enter any combination, so he can enter (with or without spaces or commas) ADE meaning he wants to process Aaaron AND Danny AND Eric.

By parsing this "ADE" I want to generate a new string and put it in a variable %List%.
That string would look like "Aaron Danny Eric" and I can issue for example a command like

@echo You have asked to process records for %List%. Proceed?

which would echo to the screen
You have asked to process records for Aaron Danny Eric. Proceed?

I've only got as far as SET /P to get the user's input :S


See More: Creating a string by parsing user input

Report •


#1
February 14, 2010 at 03:51:39
This may help a little:

@ECHO OFF
setlocal EnableDelayedExpansion
for %%a in (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) do set %%a=
set A=Aaron
set B=Barry
set C=Charlie
set D=Danny
set E=Eric

:input
set /p list=list?
if not defined list goto input
set list= !list:"=!
if not defined list goto input
set output=
for /f %%a in ('cmd /u /c set /p "=%list%"^<nul^|find /v ""') do (
    if defined %%a set output=!output! !%%a!
)
if not defined output goto input
set output=!output:~1!
echo !output!
pause


Report •

#2
February 15, 2010 at 01:37:42
Perfect!

Thanks Judago.


Report •

Related Solutions


Ask Question