Page 1 of 1

Problem with Quote character

Posted: 19 Jun 2014 08:34
by darioit
Hello,

FirSt raw of my file named E:\DATA.TXT Is:
<?xml version="1.0" encoding="UTF-8"?>


but when I run this script to manipulate string

Code: Select all

FOR /F "delims=" %%a in (%1) do set "name=%%a" &call :procName %1
goto:eof

:procName
set name1=%name:~0,9%


I got this error:
E:\>set "name1"=<?xml version="1.0" encoding="UTF-8"?>" & call :procName E:\DATA.TXT

E:\>set name1= ver 0<?xml
The filename, directory name, or volume label syntax is incorrect.

I suppose the problem is quote, how can I solve this issue?

Thanks you and Regards

Re: Problem with Quote character

Posted: 19 Jun 2014 09:07
by Squashman
The first 9 characters of that line is: <?xml ver
Why are you trying to capture just that?

Re: Problem with Quote character

Posted: 19 Jun 2014 09:13
by darioit
yes because I must split big Xml file in a little one, and I have a header "fix" long 9 byte to create a new xml, but I must read each line

Re: Problem with Quote character

Posted: 19 Jun 2014 10:18
by Squashman
You are missing quotes in your SET statement for the name1 variable.
In order to echo the variable correctly you need a ^ to escape the <.

Code: Select all

FOR /F "delims=" %%a in (data.txt) do set "name=%%a" &call :procName
pause
goto :EOF

:procName
set "name1=%name:~0,9%"
echo ^%name1%
GOTO :EOF

Re: Problem with Quote character

Posted: 19 Jun 2014 12:09
by foxidrive
Give this a go:

Code: Select all

FOR /F "delims=" %%a in (%1) do set "name=%%a" &call :procName %1
goto:eof

:procName
set "name1=%name:~0,9%"
echo "%name1%"
pause