View unanswered posts | View active topics It is currently 21 Oct 2014 12:18



Post new topic Reply to topic  [ 7 posts ] 
How proceed string with double quotes in for loop 
Author Message

Joined: 15 Feb 2012 14:02
Posts: 163
Post How proceed string with double quotes in for loop
How proceed string with double quotes in for loop?

%%A is has this value:

span class="proxy_anonymous" style="font-weight:bold; font-size:10px;"

Code:
SET type=%%A
SET type=!type:"=$!
FOR /F "tokens=1,2 delims=$" %%S IN ("%%A") DO (


And I want to get the name of class, which is here proxy_anonymous


15 Jun 2012 07:58
Profile

Joined: 10 Feb 2012 02:20
Posts: 4309
Post Re: How proceed string with double quotes in for loop
Code:
d:\ABC>type input.txt
span class="proxy_anonymous" style="font-weight:bold; font-size:10px;"
d:\ABC>type a.bat
    @echo off
    for /f "tokens=3 delims== " %%a in (input.txt) do (
    for /f "delims=" %%b in (%%a) do echo %%b
    )
    pause



d:\ABC>a
proxy_anonymous
Press any key to continue . . .


15 Jun 2012 08:07
Profile

Joined: 15 Feb 2012 14:02
Posts: 163
Post Re: How proceed string with double quotes in for loop
I know I can do this when I have the string saved in file. But the string is result from the previous loop.


15 Jun 2012 08:18
Profile

Joined: 10 Feb 2012 02:20
Posts: 4309
Post Re: How proceed string with double quotes in for loop
This is simpler anyway.

Code:
d:\ABC>type input.txt
span class="proxy_anonymous" style="font-weight:bold; font-size:10px;"
d:\ABC>type a.bat
    @echo off
    for /f "tokens=3 delims== " %%a in (input.txt) do (
    echo %%~a
    )
    pause



d:\ABC>a
proxy_anonymous


15 Jun 2012 08:23
Profile

Joined: 15 Feb 2012 14:02
Posts: 163
Post Re: How proceed string with double quotes in for loop
It doesn't work for me

Code:
    FOR /F "tokens=3 delims== " %%S IN (%%~A) DO (
    SET type=%%S %%T
    )


Span is not a command.

What does the ~ and why do you use = as delimiter?

You take different part than I thought. Does the ~ removes quotes with the style attribute? Still don't understand why 3rd token? It looks like it should be 2nd token. And the command will not go thorough because the string contains quotes.


15 Jun 2012 08:59
Profile

Joined: 15 Feb 2012 14:02
Posts: 163
Post Re: How proceed string with double quotes in for loop
Succeed!
Code:
SET A=%%A
SET A=!A:"=$!
FOR /F "tokens=1,2,3 delims=$ " %%S IN ("!A!") DO (
echo %%U


15 Jun 2012 09:21
Profile

Joined: 23 Dec 2011 13:59
Posts: 1929
Post Re: How proceed string with double quotes in for loop
doscode wrote:
It doesn't work for me

Code:
    FOR /F "tokens=3 delims== " %%S IN (%%~A) DO (
    SET type=%%S %%T
    )


Span is not a command.

What does the ~ and why do you use = as delimiter?

You take different part than I thought. Does the ~ removes quotes with the style attribute? Still don't understand why 3rd token? It looks like it should be 2nd token. And the command will not go thorough because the string contains quotes.

Its an EQUALS symbol and a SPACE as the delimiter which makes it the THIRD TOKEN!


15 Jun 2012 10:45
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 


Who is online

Users browsing this forum: Baidu [Spider], Yahoo [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.