[英]Passing a parameter containing comma to a Batch file and replace
I am calling my batch file as below 我正在按如下方式调用我的批处理文件
example.bat "abc, xyz" example.bat“ abc,xyz”
Now, inside the batch file I need to replace comma ,
with %5c%2c
现在,里面的批处理文件我需要更换逗号
,
用%5c%2c
set var1=%1
set var1=%var1:","=%5c%2c%
I even tried 我什至试过
set var1=%var1:","=%%5c%%2c%
set var1=%var1:,=%5c%2c%
But nothing worked, it actually appends the replacement at the end instead of comma. 但是没有任何效果,它实际上是在末尾附加替换而不是逗号。 Also, the parameter is printed with double quotes at the end.
另外,该参数的末尾用双引号引起来。
I am expecting the result to be : abc%5c%2c xyz
我期望结果是:
abc%5c%2c xyz
Can some one help me out resolve this ? 有人可以帮我解决这个问题吗? Thanks !
谢谢 !
You need delayed expansion for this. 您需要为此延迟扩展。 Also, to get rid of the double quotes, you should use
%~1
instead of %1
. 另外,要摆脱双引号,应使用
%~1
而不是%1
。 You were right to double up on the percent signs to display literal %
s. 您应该加倍百分号以显示文字
%
s。
@echo off
setlocal enabledelayedexpansion
set var1=%~1
set var1=!var1:,=%%5c%%2c!
echo !var1!
pause
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.