Page 1 of 1

Verifying the content of the read string from input file

Posted: 09 Sep 2009 15:38
by Fredy
Hello,
I want to verify the content of the text read from the input file, before I transfer it to an out file.
I did try to put its content into a variable, but it doesn't work.
Some body can help me please?
Thanks.

for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
Set subStr=%%k:~0,12%%
)

However the following works:
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
echo.%%k>> "OutputFile"
)

Posted: 10 Sep 2009 08:50
by avery_larry
substrings do not work on for variables (%%k). You have to assign a "normal" variable first and then do the substring.

Since you're inside a for loop, you'll have to use delayedexpansion like this:

*untested*

Code: Select all

@echo off
setlocal enabledelayedexpansion
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
   set "tmpvar=%%~k"
   set "subStr=!tmpvar:~0,12!"
)


You could also do this without delayedexpansion:

Code: Select all

@echo off
for /F "tokens=1* delims=]" %%j in ('type "%param%" ^| find /V /N ""') do (
   set "tmpvar=%%~k"
   call set "subStr=%%tmpvar:~0,12%%"
)