Page 1 of 1
How proceed string with double quotes in for loop
Posted: 15 Jun 2012 07:58
by doscode
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: Select all
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
Re: How proceed string with double quotes in for loop
Posted: 15 Jun 2012 08:07
by foxidrive
Code: Select all
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 . . .
Re: How proceed string with double quotes in for loop
Posted: 15 Jun 2012 08:18
by doscode
I know I can do this when I have the string saved in file. But the string is result from the previous loop.
Re: How proceed string with double quotes in for loop
Posted: 15 Jun 2012 08:23
by foxidrive
This is simpler anyway.
Code: Select all
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
Re: How proceed string with double quotes in for loop
Posted: 15 Jun 2012 08:59
by doscode
It doesn't work for me
Code: Select all
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.
Re: How proceed string with double quotes in for loop
Posted: 15 Jun 2012 09:21
by doscode
Succeed!
Code: Select all
SET A=%%A
SET A=!A:"=$!
FOR /F "tokens=1,2,3 delims=$ " %%S IN ("!A!") DO (
echo %%U
Re: How proceed string with double quotes in for loop
Posted: 15 Jun 2012 10:45
by Squashman
doscode wrote:It doesn't work for me
Code: Select all
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!