简体   繁体   中英

batch remove a substring variable from another string variable

so I've got the following code:

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

wich 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 ?

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=!"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM