批处理替换中含有延迟变量? 5
你好,我想把ggg=777,hhh=888,iii=999里的ggg=777替换成ggg=777666,但是下面的代码输出的是777=ggg=777666=777,hhh...
你好,我想把ggg=777,hhh=888,iii=999里的ggg=777替换成ggg=777666,但是下面的代码输出的是777=ggg=777666=777,hhh=888,iii=999,请问正确的应该这么写啊?
@echo off
setlocal enabledelayedexpansion
set testfile02=D:\test02.csv
rem test02.csv里就一行,ggg=777,hhh=888,iii=999
for /f "delims=" %%x in (%testfile02%) do (
set total=%%x
for /f "tokens=1-3 delims=," %%a in (%testfile02%) do (
set first=%%a
call set zxc=%%total:!first!=!first!666%%
echo !zxc!
)
)
endlocal 展开
@echo off
setlocal enabledelayedexpansion
set testfile02=D:\test02.csv
rem test02.csv里就一行,ggg=777,hhh=888,iii=999
for /f "delims=" %%x in (%testfile02%) do (
set total=%%x
for /f "tokens=1-3 delims=," %%a in (%testfile02%) do (
set first=%%a
call set zxc=%%total:!first!=!first!666%%
echo !zxc!
)
)
endlocal 展开
1个回答
展开全部
bat的这种字符替换方式是有很大局限性的,比如无法替换=和*
复制粘贴到记事本,另存为xx.bat,编码选ANSI
复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echo off
rem bat/批处理实现字符串替换
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "file=D:\test02.csv"
>"%tmp%\v.v" echo;WSH.echo replace(WSH.StdIn.ReadAll,WSH.Arguments(0),WSH.Arguments(1))
type "%file%"|cscript -nologo -e:vbscript "%tmp%\v.v" "ggg=777" "ggg=777666"
:end
echo;%#% +%$%%$%/%@% %z%
pause
exit
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询