Hi Experts,
I have a requirement to replace a search string ( which has been set inside a block ) with some replacement string.
Below is the code I have. Which is not working.
@echo off
setlocal enabledelayedexpansion
set SAMPLE=sample
set REPLACETEXT=hello
if %SAMPLE% == sample (
SET string=how abt bath
set SEARCHTEXT=bath
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
echo !modified!
)
I am not sure about the exact syntax to nest the variables inside a block.
Could someone help me with this script ?
Thanks in Advance
Sambasiva
Replacing a string inside a block
Moderator: DosItHelp
Re: Replacing a string inside a block
Code: Select all
@echo off
setlocal enabledelayedexpansion
set SAMPLE=sample
set REPLACETEXT=hello
if %SAMPLE% == sample (
SET string=how abt bath
set SEARCHTEXT=bath
for /F "tokens=1,2" %%a in ("!SEARCHTEXT! !REPLACETEXT!") do SET modified=!string:%%a=%%b!
echo !modified!
)
Re: Replacing a string inside a block
Excellent...It worked..
Thanks a lottttttttttttttttttt....
Thanks a lottttttttttttttttttt....