Page 1 of 1

mid function in for loop

Posted: 22 Jun 2009 07:56
by BD_CDN
Hi

I'm trying to extract characters from a string using the mid function inside a for loop. The string is from a text file. The characters I extract are used to build a command in a new batch file. I can't get the mid function to work in a for loop.

Any help???

Here's an example input file:
042N05
042O09
042O10

Here's what I want the command to look like in the new batch file:
call cv.bat 042 n 05
call cv.bat 042 o 09
call cv.bat 042 o 10

Here's the code:

set /p LFname=Enter the list file name:
set /p BFname=Enter the new batch file name:

setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (%LFname%) do (
echo call cv.bat %%a:~0,3 %%a:~3,1 %%a:~4,2 >> %BFname%
)


Thanks

Posted: 22 Jun 2009 11:44
by avery_larry
UNTESTED:

Code: Select all

set /p LFname=Enter the list file name: 
set /p BFname=Enter the new batch file name:

setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (%LFname%) do (
   set tmp_var=%%a
   echo call cv.bat !tmp_var:~0,3! !tmp_var:~3,1! !tmp_var:~4,2!>>%BFname%
)

solved

Posted: 22 Jun 2009 13:03
by BD_CDN
That works great.

Thanks!