Problem with Quote character

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Problem with Quote character

#1 Post by darioit » 19 Jun 2014 08:34

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

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Problem with Quote character

#2 Post by Squashman » 19 Jun 2014 09:07

The first 9 characters of that line is: <?xml ver
Why are you trying to capture just that?

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: Problem with Quote character

#3 Post by darioit » 19 Jun 2014 09:13

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

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Problem with Quote character

#4 Post by Squashman » 19 Jun 2014 10:18

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem with Quote character

#5 Post by foxidrive » 19 Jun 2014 12:09

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

Post Reply