Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
doscode
- Posts: 175
- Joined: 15 Feb 2012 14:02
#1
Post
by doscode » 15 Jun 2012 07:58
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
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 15 Jun 2012 08:07
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 . . .
-
doscode
- Posts: 175
- Joined: 15 Feb 2012 14:02
#3
Post
by doscode » 15 Jun 2012 08:18
I know I can do this when I have the string saved in file. But the string is result from the previous loop.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 15 Jun 2012 08:23
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
-
doscode
- Posts: 175
- Joined: 15 Feb 2012 14:02
#5
Post
by doscode » 15 Jun 2012 08:59
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.
-
doscode
- Posts: 175
- Joined: 15 Feb 2012 14:02
#6
Post
by doscode » 15 Jun 2012 09:21
Succeed!
Code: Select all
SET A=%%A
SET A=!A:"=$!
FOR /F "tokens=1,2,3 delims=$ " %%S IN ("!A!") DO (
echo %%U
-
Squashman
- Expert
- Posts: 4477
- Joined: 23 Dec 2011 13:59
#7
Post
by Squashman » 15 Jun 2012 10:45
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!