开发者

How to perform substring substitution when the substring contains the equal sign?

开发者 https://www.devze.com 2023-01-17 17:02 出处:网络
In Window开发者_Go百科s Batch files, you can use this syntax to perform search&replace on variables:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号