Extract Chars in Var

October 28, 2010 at 16:02:55
Specs: Windows XP
I have a batch script where I am doing a for loop. In the referencing txt file each line data1:data2 The number of characters in data1 can be of variable length but data2 is always the same length, both values separated by a :

No what in my loop there are times where I need to take the entire line data1:data2 as well as times where I take just data1 and others where I take data2. What I am doing in short would be:

for /f "tokens=*" %%i in (datafile.txt) do call :getFiles %%i

set statinfo=%1
set data1=%statinfo:~0,7%
set data2=%statinfo:~8%

This is as close as I have come, but as you will see I am specifying a set value of the first 7 chars for data1 and thats the problem. I'm not sure how to either read all chars up to special character of : or read all chars minus the last 7, either of which would work. Vars statinfo and data2 work fine so dont need assistance with those two.

See More: Extract Chars in Var

Report •

October 28, 2010 at 16:52:16
for /f "tokens=1* delims=:" %%i in (datafile.txt) do (
  echo %%i
  echo %%j
Or, keeping with your subfunction:
for /f "tokens=1* delims=:" %%i in (datafile.txt) do call :getFiles "%%i" "%%j"

How To Ask Questions The Smart Way

Report •

October 28, 2010 at 18:15:48
Perfect, thanks much!

Report •

Related Solutions

Ask Question