I can use exclamation mark in percent expand?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

I can use exclamation mark in percent expand?

#1 Post by einstein1969 » 23 May 2014 04:21

Hi,

I have the necessity to use the percent expand in a SET with the unary operator "!"

I have tried in this mode but not work. I prefer not use the toggle to disabledelayedexpansion, primarly for performance problem.

It is possible?

Code: Select all

@echo off
setlocal disabledelayedexpansion

set "E=!!"

setlocal enabledelayedexpansion

(
set /a "a=!E!10"
set /a "b=%E%10"
)

echo !a! !b!


result:

Code: Select all

1 10



einstein1969

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: I can use exclamation mark in percent expand?

#2 Post by penpen » 23 May 2014 05:14

If you are not allowed to just escape the '!', then you might do it this way:
@echo off
setlocal disabledelayedexpansion

set "E=!"

setlocal enableDelayedExpansion
(
set "a=1"
set /A "b=^!1"
set /A "c=!E!1"
echo(!a!, !b!, !c!
)
endlocal

penpen

jeb
Expert
Posts: 1063
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: I can use exclamation mark in percent expand?

#3 Post by jeb » 23 May 2014 05:45

Instant extension should work

Code: Select all

set /a "b=%E:!=^!%10"


jeb

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

Re: I can use exclamation mark in percent expand?

#4 Post by einstein1969 » 23 May 2014 09:57

Thanks penpen and Thanks Jeb.

Work like charm.

I don't probe the simple caret escape! :oops:

einstein1969

Post Reply