0

I've got the following code:

set "alpha=!alpha:%%~nxA=!
set "data=!data:%p2_dir%=!

which works regardless of what %p2_dir% value is,

now here's my problem, I would like to remove !alpha! from !data! and store it in a variable called dwa.

Example:

alpha=aaa\bbb\

data=aaa\bbb\ccc

dwa=ccc

in other topics they want to remove a variable like %substring% not !substring!

the problem is, since I've got 2 !var! variables I cannot use the following command:

"dwa=!data:!alpha!=!"

otherwise it returns

data:=

I tried sending values of !alpha! and !data! in a txt file then saving it using

set /p alpha2=< alpha.txt

but the result is still the same: alpha2 will be saved as !alpha2!

How can I do this?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Vylaxez
  • 21
  • 3
  • 1
    Please show us a little bit more code in-context. There may be other ways of accomplishing whatever your requirement is. – Magoo Mar 02 '18 at 14:17
  • 1
    `for /F %%a in ("!alpha!") do set "dwa=!data:%%a=!"`. I suggest you to carefully read [this answer](https://stackoverflow.com/a/10167990/778560) although the topic seems to be different... – Aacini Mar 02 '18 at 14:36
  • What Magoo is trying to lead you too is that if you are not inside a code block, there is no need to use delayed expansion for the inner variable. So we really need to see more of your code to understand in what context those lines are executing. – Squashman Mar 02 '18 at 15:27
  • thx this is exactly what I was looking for @Aacini – Vylaxez Mar 02 '18 at 15:31

1 Answers1

1

So I ended up using @Aacini answer:

set "alpha=!alpha:%%~nxA=!
set "data=!data:%p2_dir%=!
for /F %%a in ("!alpha!") do set "dwa=!data:%%a=!"
Vylaxez
  • 21
  • 3