arrays - 为什么我的批处理脚本不能正确替换?
问题描述
我有这个脚本来替换文本文件中的一些单词。不知道对不对:
@echo off
setlocal EnableDelayedExpansion
set count=0
set j=0
set i=0
for /f "tokens=* delims=" %%c in ( '"type test.txt"') do (
SET string=%%b
echo %%c >>test2.txt
)
for /F %%a in (params.txt) do (
set array[!i!]=%%a
set /A i+=1
)
for /F "tokens=1 delims==" %%p in (params.txt) do (
set array2[!j!]=%%p
set /A j+=1
)
set /A i-=1
for /l %%r in (%count% , 1, %i%) do (
set replace=!array2[%%r]!
echo %repace%
set replaced=!array[%%r]!
echo replaced
set /A count+=1
call :reemplaza
)
:reemplaza
if %count% LSS %i% (
for /f "tokens=* delims=" %%b in ( '"type test2.txt"') do (
SET string=%%b
SET modified=!string:%replace%=%replaced%!s
echo.!modified! >>auxiliar.txt
)
pause
del test2.txt
ren auxiliar.txt test2.txt
)
第一个循环是正确的,但在第二个循环中这样做:
我想替换:name=awachens for name=awachenss
所以取下一个参数并打印:
姓名=awachens=姓=大声笑
问候 !
解决方案
推荐阅读
- python - 如何为每个句子的字母获取字母索引?
- python - Pandas 将 Nan 分类为额外的 Max Bin
- java - DropWizard中的JDBI 3,按需重用连接
- javascript - Flex容器:有没有办法在容器包装时拉伸第一个项目的高度
- python - 从列表索引为 numpy 数组赋值
- javascript - Fullcalendar 事件被水平压缩
- python - Python日志记录没有发生
- excel - 如果值在列表中,则添加行
- python - 使用正则表达式在列中提取月份 - Python
- azure-devops - 从触发多回购 Azure 管道中排除分支