can any 1 explain me abt delims and token in batch files???

I need some explanation on tokens and delims command used in batch file. CAn any 1 explain it in detail please

g-one8 years ago
First let me say sorry for my imperfect English. The g in my nickname is for German...

I want to give you a sample batch file to show it:

:: snip *.bat

@echo off &setlocal
set var=abc:def:ghi,jkl mno

echo 1) default delimiter
:: The default delimiters are space and tab.
:: If you don't set any delimiter the default will be used.
:: Let's see the 2 parts of the string.
for /f "tokens=1,2" %%a in ("%var%") do echo 1st token "%%a" - 2nd token "%%b"
echo.

echo 2) use one delimiter
:: Let's see the first 2 parts of the string if we use ":" as delimiter.
for /f "delims=: tokens=1,2" %%a in ("%var%") do echo 1st token "%%a" - 2nd token "%%b"
echo.

echo 3) use more then one delimiter
:: Let's see the parts of the string if we use ":" and "," as delimiters.
for /f "delims=:, tokens=1-4" %%a in ("%var%") do echo 1st token "%%a" - 2nd token "%%b" - 3rd token "%%c" - 4th token "%%d"
echo.

echo 4) use default delimiter and show only the 2nd part of the string
:: note: we start with the 2nd token - thats why the 2nd token is in %%a not in %%b
for /f "tokens=2" %%a in ("%var%") do echo 2nd token "%%a"
echo.

echo 5) use a delimiter and show the 1st part and the leftover
:: Let's see what the wildcard is good for
for /f "delims=: tokens=1*" %%a in ("%var%") do echo 1st token "%%a" - leftover "%%b"
echo.

echo 6) Let's show the FOR - Help
pause
cls
for /? |more

:: snap *.bat
kevinhannan8 years ago
I Googled it, and there's plenty of help - try this link, there is a forum, too.

http://ss64.com/index.html