1

I have a .bat file that needed to substring a variable with another variable. The the substring will be inside a loop. I have two variable inside this loop.

echo %%i  

echo %targetPath%

%%i is the full string. And I have to remove part of %%i if found a match string with %targetPath%

My coding which is not working.

echo  %%i%:%targetPath%=%

My couldn't get it to work because I am confused with the %%name and %name%. This is my expected result. In php , we have a substring function that able to pass the fullstring into substring function and a keyword to be match. And this is what I trying to achieve

fullstr=abcdefghijk
keyword=abcd

result=efghijk

Current working code

setlocal EnableDelayedExpansion 

set "targetPath=%~dp0in"

for /r "%targetPath%" %%i in (.) do (

set "str=%%i"
echo  !str:%targetPath%=!

)

Current output

echo  !str:C:\Users\vuser01\Desktop\Texture Packer\libgdxtools\in=!
Leon Armstrong
  • 1,285
  • 3
  • 16
  • 41
  • This type of management is fully described at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990), although the topic is different. – Aacini Sep 20 '17 at 14:46

1 Answers1

2

you can use delayed expansion:

setlocal enableDelayedExpansion
set "target=some"
for %%i in ("something") do (
 set "var=%%i"
 echo !var:%target%!
)
npocmaka
  • 55,367
  • 18
  • 148
  • 187