batch file to separate parts of one string?

January 29, 2011 at 23:45:02
Specs: Windows 7
How do I get a batch file to separate parts of one string?
I am trying to write a batch file that will read a line from a text file, on that one line will be something like "bob smith 25 red". I want to then be able to prompt my program for the first name and it return "bob" or ask for the age and it give "25", and so on. All the information must be on the same line of the text file, but will have spaces in between each piece of information to be separated.

See More: batch file to separate parts of one string?

Report •


#1
January 30, 2011 at 00:08:45
:: ==========================================
::
:: bean.bat Sun 30-01-2011 15:02:02.11
@echo off & setLocal enableDELAYedeXpansion

for /f "tokens=1-4 delims= " %%a in ("bob smith 25 red") do (
set F=%%a
set L=%%b
set A=%%c
set C=%%d
)
set /p P=which part ? F L A C :
echo.!%P%!


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
January 30, 2011 at 00:24:59
Thank you. This worked great, and helps me a lot.

Report •

Related Solutions


Ask Question