Replacing text in %var%

  • Thread starter Thread starter Ray at
  • Start date Start date
R

Ray at

Hi group,

Can anyone tell me how to replace a piece of a string with another piece of
a string within a variable? For example:

SET X=C:\Ray\path
[command to do replace "Ray" with "Joe" in %X%]
ECHO X
Yeilds: C:\Joe\Path

(The "Ray" and "Joe" values will be hard-coded into my .bat file.)

In searching, I found this article:
http://groups.google.com/groups?threadm=04b901c2c2f7$192549e0$89f82ecf@TK2MSFTNGXA01

That appears that it'll work after I filter out all the file operations
steps, as I'm not concerned with replacing text in a file. But, I suspect
there would be a different way to do it that isn't as complex. If not, I
can probably piece something together with what I'm reading in tips 4194 and
5700 at jsiinc.com.

Thank you,

Ray at work
 
Ray at said:
Hi group,

Can anyone tell me how to replace a piece of a string with another piece of
a string within a variable? For example:

SET X=C:\Ray\path
[command to do replace "Ray" with "Joe" in %X%]
ECHO X
Yeilds: C:\Joe\Path

(The "Ray" and "Joe" values will be hard-coded into my .bat file.)

In searching, I found this article:
http://groups.google.com/groups?threadm=04b901c2c2f7$192549e0$89f82ecf@TK2MSFTNGXA01

That appears that it'll work after I filter out all the file operations
steps, as I'm not concerned with replacing text in a file. But, I suspect
there would be a different way to do it that isn't as complex. If not, I
can probably piece something together with what I'm reading in tips 4194 and
5700 at jsiinc.com.

Thank you,

Ray at work

set X=%X:Ray=Joe%
 
at said:
Hi group,

Can anyone tell me how to replace a piece of a string with another piece of
a string within a variable? For example:
As you can see here the match isn't case sensitive

@echo off & setlocal EnableExtensions
SET X=C:\Ray\path
Echo/Original =%X%
set X=%X:Ray=Joe%
Echo/Changed through set X=%%X:Ray=Joe%% = %X%
SET X=C:\Ray\path
set X=%X:ray=Joe%
Echo/Changed through set X=%%X:ray=Joe%% = %X%

for details see in a cmd window:
set /?
 
Back
Top