我试图了解 Windows 批处理中的字符串替换实际上是如何工作的并且遇到了问题。
@echo off
set var=wild
set varnew=%var:l=n%
echo var is: %var%
echo varnew is: %varnew%
Run Code Online (Sandbox Code Playgroud)
确实有效;它生成预期的输出:
var is: wild
varnew is: wind
Run Code Online (Sandbox Code Playgroud)
但这不是(示例目录“Main”):
@echo off
for /D %%G IN (*) do (
setlocal
echo G is: %%G
set _srcp=%%G
echo _srcp is %_srcp%
rem set _newp=%_newp:ai=_01_% <-- confused variable
set _newp=%_srcp:ai=_01_%
echo._newp is: %_newp%
endlocal
)
Run Code Online (Sandbox Code Playgroud)
它生成此输出:
G is: Main
_srcp is Main
_newp is: %_srcp:ai=_01_
Run Code Online (Sandbox Code Playgroud)
我希望代码生_newp is: M_01_n成为最后一行。我在这里真的没有想法,有人可以指出我正确的方向吗?
BB