Page 1 of 1

Variable manipulation

Posted: 26 Mar 2012 03:33
by ankycooper9
Let say I have 2 variables

Code: Select all

set var1=hello:\how\areyou.i'mgr8
set var2=hello:\how\are

now I have to remove contents of var2 from var1
(The desired result in the above example would be var1=you.i'mgr8 )

I have ftied the following but does not work

Code: Select all

set var1=!var1:!var2!=!


Please help

Re: Variable manipulation

Posted: 26 Mar 2012 04:43
by dbenham

Code: Select all

set var1=!var1:%var2%=!

If you are in a situation where you cannot use immediate expansion, then:

Code: Select all

@echo off
setlocal enableDelayedExpansion
(
  set var1=hello:\how\areyou.i'mgr8
  set var2=hello:\how\are
  for /f "delims=" %%S in ("!var2!") do set var1=!var1:%%S=!
)


Dave Benham

Re: Variable manipulation

Posted: 26 Mar 2012 07:14
by !k
w/o DelayedExpansion

Code: Select all

call set var1=%%var1:%var2%=%%

Re: Variable manipulation

Posted: 26 Mar 2012 09:24
by ankycooper9
Thanks dbenham it woked!!