How to perform substring substitution when the substring contains the equal sign?
In Window开发者_Go百科s Batch files, you can use this syntax to perform search&replace on variables:
set myvar=%myvar:foo=bar%
How to do this, however, when “foo” or “bar” include an equal sign? Escaping it with ^
does not seem to work…
Thank you.
Instead of battling with cmd.exe's quirks, why not use vbscript instead?
Set objArgs = WScript.Arguments
strOld=objArgs(0)
strNew=objArgs(1)
str=Replace(WScript.StdIn.ReadAll,vbCrLf,"")
WScript.Echo Replace(str,strOld,strNew)
Save the above as replace.vbs
Usage:
C:\test>echo test| cscript //nologo replace.vbs te mi
mist
精彩评论