Page 1 of 1

Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 10:01
by Pilou
Hi,

I would like to know if it's possible to manage strings with at the same time & and | and " ? here is a snippet of my failed attemps :

Code: Select all

@echo off
setlocal enabledelayedexpansion

ver

echo ==============

set ONE=u "A&B" v
set TWO=ww %ONE% || xx

echo ONE=%ONE%
echo TWO=%TWO%

echo ==============

set ONE=u "A&B" v
set TWO=ww %ONE% ^|^| xx

echo ONE=%ONE%
echo TWO=%TWO%

echo ==============

set "ONE=u "A&B" v"
set "TWO=ww %ONE% || xx"

echo ONE=%ONE%
echo TWO=%TWO%

echo ==============

set "ONE=u "A^&B" v"
set "TWO=ww %ONE% || xx"

echo ONE=%ONE%
echo TWO=%TWO%


which gives :

Code: Select all

Microsoft Windows [Version 6.1.7601]
==============
ONE=u "A&B" v
TWO=ww u "A&B" v
==============
ONE=u "A&B" v
TWO=ww u "A&B" v
==============
'B" v"' is not recognized as an internal or external command,
operable program or batch file.
ONE=u
TWO=ww u
==============
'B" v || xx"' is not recognized as an internal or external command,
operable program or batch file.
ONE=u "A&B" v
TWO=ww u


Thanks a lot by advance :)

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 10:49
by Squashman
Why have delayed expansion enabled if you are not going to use it. :wink:

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 11:19
by Pilou
Great ! replacing % by ! solves the problem indeed !

In fact, I just enable delayed expansion by reflex but I didn't know that it has also an effet outside a for loop :wink:

Big, big thanx :!:

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 11:30
by foxidrive
Pilou wrote:Great, repleacing % by ! solves the problem indeed !


Do you know what happens to ! characters?

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 11:52
by Pilou
foxidrive wrote:
Pilou wrote:Great, repleacing % by ! solves the problem indeed !


Do you know what happens to ! characters?


Hum, no... I hope never get one in my data :mrgreen:

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 11:56
by foxidrive
Pilou wrote:Hum, no... I hope never get one in my data :mrgreen:


Ok. It creates a mini blackhole in the vicinity of your batch file and they get gobbled up in the event horizon.

:D

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 12:34
by Squashman
foxidrive wrote:
Pilou wrote:Great, repleacing % by ! solves the problem indeed !


Do you know what happens to ! characters?

foxidrive (a.k.a Devils Advocate) :twisted:

Re: Is ther a way to manage strings with & and | and " ?

Posted: 06 Jul 2015 22:09
by foxidrive
Squashman wrote:foxidrive (a.k.a Devils Advocate) :twisted:


I'm married to his sister - it goes with the turf. ;)