For /F problem with double quote and space and other char...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 947
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

For /F problem with double quote and space and other char...

#1 Post by einstein1969 » 15 Oct 2013 11:23

Hi,

I'm going crazy with the special syntax of the For / F!

I have read this HOW TO: FOR /F Disabling EOF or using a quote as delim but with no result

I have a var that can contain a space and can use double quote at sorround.

Can the for /f eliminate space and double quote and leave the rest?

thanks, Einstein1969

aGerman
Expert
Posts: 4656
Joined: 22 Jan 2010 18:01
Location: Germany

Re: For /F problem with double quote and space and other cha

#2 Post by aGerman » 15 Oct 2013 15:36

I'm not quite certain what you're looking for :?
Sounds like

Code: Select all

set "var="Hello World""
echo %var%
set "var=%var:"=%"
echo %var%
echo %var: =%

but sounds also like

Code: Select all

set "var="Hello World""
echo %var%
for /f "delims=" %%i in ("%var%") do for /f "tokens=1,2" %%j in ("%%~i") do echo %%j&echo %%k

or like

Code: Select all

set "var="Hello World""
echo %var%
for /f tokens^=1^,2^ delims^=^"^  %%i in ("%var%") do echo %%i&echo %%j

Regards
aGerman

einstein1969
Expert
Posts: 947
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: For /F problem with double quote and space and other cha

#3 Post by einstein1969 » 15 Oct 2013 16:04

aGerman wrote:I'm not quite certain what you're looking for :?
Sounds like

Code: Select all

set "var="Hello World""
echo %var%
set "var=%var:"=%"
echo %var%
echo %var: =%

but sounds also like

Code: Select all

set "var="Hello World""
echo %var%
for /f "delims=" %%i in ("%var%") do for /f "tokens=1,2" %%j in ("%%~i") do echo %%j&echo %%k

or like

Code: Select all

set "var="Hello World""
echo %var%
for /f tokens^=1^,2^ delims^=^"^  %%i in ("%var%") do echo %%i&echo %%j

Regards
aGerman


Thanks a lot! Work!

The third seems faster.

Einstein

aGerman
Expert
Posts: 4656
Joined: 22 Jan 2010 18:01
Location: Germany

Re: For /F problem with double quote and space and other cha

#4 Post by aGerman » 15 Oct 2013 16:18

The third seems faster.

Maybe. But does it really matter :?

The question is if you're aware that all of them are working completely different?
Test again with

Code: Select all

set "var="Say "hello" to the World""


Regards
aGerman

einstein1969
Expert
Posts: 947
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: For /F problem with double quote and space and other cha

#5 Post by einstein1969 » 15 Oct 2013 17:11

aGerman wrote:
The third seems faster.

Maybe. But does it really matter :?

The question is if you're aware that all of them are working completely different?
Test again with

Code: Select all

set "var="Say "hello" to the World""


Regards
aGerman


I have seen :?

Post Reply