set "$VAR=^!$VAR:*==^!" not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

set "$VAR=^!$VAR:*==^!" not working

#1 Post by Ed Dyreen » 02 Jun 2011 00:46

this works:
set "$VAR=^!$VAR:*¦=^!"

this doesn't:
set "$VAR=^!$VAR:*==^!"

this works again:
for /f "tokens=1,2* delims==" %%a in ( 'set $VAR' ) do echo.tokens=%%b_ %\n2%

Is it possible to make it work without for ?

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: set "$VAR=^!$VAR:*==^!" not working

#2 Post by orange_batch » 02 Jun 2011 01:50

How is this? Sorry I can't test it right now.

Code: Select all

set $VAR=^!$VAR:*=^=^!

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set "$VAR=^!$VAR:*==^!" not working

#3 Post by Ed Dyreen » 02 Jun 2011 02:11

Ok so in the above I was trying it in a macro but I can't even make it work outside a macro, even this don't work: :?
set "$?=hello=there"
set $var=%$?:*==%
echo.$var=%$var%_
pause
exit

result:
==%
not expected at this time.

neither does this:
set $var=%$?:*^==% rem this evaluates to set "$var=hello=there"
or this:
set $var=%$?:*=^=%

zia
Posts: 1
Joined: 02 Jun 2011 03:47

Re: set "$VAR=^!$VAR:*==^!" not working

#4 Post by zia » 02 Jun 2011 04:01

I have problem with this script if any one of you people have the solution are welcome
In this below script i want that script after substracting 1 from day the day should desplay the result in double figure like 01..........09. this work fine when today date is in double figure. Sorry for my poor english.

SETLOCAL

REM *********** SET Value from DATE *************
set yy=%date:~-4%
set dd=%date:~-7,2%
set mm=%date:~-10,2%

set /a dd =%dd%-1

cd\
e:
cd e:\Archived-Repo\%yy%-%mm%-%dd%

My personal id is ziauktk84@yahoo.com any suggestion from any body are welcome

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: set "$VAR=^!$VAR:*==^!" not working

#5 Post by dbenham » 02 Jun 2011 06:59

Hi Ed,

Isn't this a special case relevant to How to replace "=","*", ":" in a variable - a topic you already visited?

Your FOR solution will not give the correct answer for a string like "part1==part2". The correct answer is "=part2" and the FOR technique returns "part2". I think a variation of what amel27 does in the above link could be developed to give the exact solution.

One other suggestion - We are still learning the ins and outs of macros, and they are not used by the general audience. So before posting questions related to macro development code, you should probably see if the question can be distilled to its fundamentals without any unnecessary macro "baggage". In this case you managed to do that by your 2nd post. (It sounds like I don't like macros - but you know I do!)

Dave Benham

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: set "$VAR=^!$VAR:*==^!" not working

#6 Post by Ed Dyreen » 02 Jun 2011 07:10

Hmmm, I understand it know, ... guess I owe u again :wink:

Post Reply