1.

Solve : Replace str in variable with parameters passed to batch?

Answer»

Hi
I can do this

C:\set a=whatisthis
C:\set b=%a:what=that%

C:\echo %b%
thatisthis

But when i try to do same in batch as
----------outtest.bat----------------
@echo off
setlocal enabledelayedexpansion
SET b=%1
SET S=%2 -- search part
SET R=%3 -- REPLACE part
ECHO b IS %b%
set NEWCMD=%b:%S%=%R%%
ECHO NEW CMD IS %NEWCMD%
---------------------------------------------

C:\outtest.bat whatisthis what that
B IS whatisthis
NEW CMD IS SR%

Since search is variable i am putting % before and after it.. Same is for replace part

Can someone help

Regardscall set NEWCMD=%%b:%S%=%R%%%
or
call set NEWCMD=%%b:%2=%3%%

i think there is other METHOD ALSO.



Discussion

No Comment Found