|
diane
新手上路

积分 6
发帖 1
注册 2006-7-13
状态 离线
|
『楼 主』:
用for循环进行文本替换,某些特殊字符无法替换。求助!
使用 LLM 解释/回答一下
在批处理文件中,将文件a.txt 中的某些文字替换成别的文字
for /f "tokens=* delims= " %%i in (a.txt) do (
set n=%%i
set n=!n:aaa=bbb!
echo !n! | find /I "ECHO"
IF ERRORLEVEL 1 (
echo !n! >> temp.txt
) else (
echo. >>temp.txt
)
)
copy temp.txt a.txt
如果字串aaa中含有空格,或者点号.都不能中正确替换,有哪位大侠有更好的解决方案? 谢谢谢谢谢。。。。
In batch files, replacing certain text in file a.txt with other text
for /f "tokens=* delims= " %%i in (a.txt) do (
set n=%%i
set n=!n:aaa=bbb!
echo !n! | find /I "ECHO"
IF ERRORLEVEL 1 (
echo !n! >> temp.txt
) else (
echo. >>temp.txt
)
)
copy temp.txt a.txt
If the string aaa contains spaces or dots ., it cannot be replaced correctly. Is there any expert who has a better solution? Thanks thanks thanks...
|
|
2006-7-13 20:50 |
|
|
buddiyar
初级用户
 
积分 160
发帖 75
注册 2006-6-28
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
set n=!n:aaa=bbb!
同是新手上路 似乎你比我要厉害哦
呵呵 不介意的话 点解一下这句先
谢谢啊^_^
set n=!n:aaa=bbb!
You are also a newbie, it seems you are more capable than me
Hehe, if you don't mind, please explain this sentence first
Thanks ^_^
|
|
2006-7-15 00:31 |
|
|
chenall
银牌会员
    
积分 1276
发帖 469
注册 2002-12-23 来自 福建泉州
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
按照楼主要求,基本上是无法达到.
只好再加几句替换的命令了.将所有可能的组合全部加进来.
不知这个作什么用,最终的目的是什么?若能再详细一点(最好贴上你的原文件),或许有办法.
TO 2楼的:
set n=!n:aaa=bbb!
将变量n中的aaa替换成bbb
According to the building owner's requirements, basically it cannot be achieved.
I have to add a few more replacement commands. Add all possible combinations in.
I don't know what this is for, what is the final purpose? If it can be more detailed (preferably paste your original file), maybe there is a way.
TO the 2nd floor:
set n=!n:aaa=bbb!
Replace aaa with bbb in variable n
|

QQ:366840202
http://chenall.net |
|
2006-7-16 20:36 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Re diane:
set 的串替换是支持 句点和空格 的,请测试以下的示例,正常情况下,它应该显示出的我的英文name。你的问题应该与 a.txt 中的其他内容有关。
另外,echo !n! 至以下数句,可使用一句 echo.!n! >> temp.txt 等同替换。
@echo off & setlocal EnableDelayedExpansion
for /f "tokens=* delims=" %%i in ("Hello world.") do (
set n=%%i
set n=!n:ld.=t!
set n=!n:o w= S!
set n=!n:He=Wi!
echo !n!
)
致黛安:
set的字符串替换支持句点和空格,请测试以下示例,正常情况下应该显示出我的英文name。你的问题应该与a.txt中的其他内容有关。
另外,echo!n!到以下几句,可使用一句echo.!n! >> temp.txt等同替换。
@echo off & setlocal EnableDelayedExpansion
for /f "tokens=* delims=" %%i in ("Hello world.") do (
set n=%%i
set n=!n:ld.=t!
set n=!n:o w= S!
set n=!n:He=Wi!
echo !n!
)
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-7-20 01:28 |
|
|
buddiyar
初级用户
 
积分 160
发帖 75
注册 2006-6-28
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
呵呵 谢谢chenall的解释
不过似乎 willsort大哥的来得更清楚明白一些
一直很敬佩的哦
Hehe, thanks for chenall's explanation. But it seems that brother willsort's is more clear and understandable. Always admired you a lot
|
|
2006-7-21 20:18 |
|
|
oilio
高级用户
    前进者
积分 641
发帖 303
注册 2007-1-10
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
晕死了,看不太懂啊。!n!是啥啊?
Oh, this is really confusing. What on earth is!n!?
|

我相信总有一天,总会遇到一个人可以相濡以沫、相吻以湿! |
|
2007-1-16 03:00 |
|
|
minmin888
初级用户
 
积分 127
发帖 62
注册 2007-4-19
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
学到东西,多谢willsort
Learned something, thanks willsort
|
|
2007-4-21 03:45 |
|
|
xielei198210
新手上路

积分 4
发帖 2
注册 2007-4-20
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
为什么
echo.!n! >> temp.txt
一句可以可以判定echo并删除之呢?
Why can the sentence `echo.!n! >> temp.txt` be used to determine and delete echo?
|
|
2007-4-24 04:26 |
|
|
xielei198210
新手上路

积分 4
发帖 2
注册 2007-4-20
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
为什么echo.!n! >> temp.txt
可以判定echo非法字符并删除之呢?
并且结果里原来是空格的现在没了,怎么保留空格呢?
并且“!”也无法保留下来,怎么办呢?
Last edited by xielei198210 on 2007-4-23 at 03:34 PM ]
Why can echo.!n! >> temp.txt determine that echo is an illegal character and delete it?
And the original spaces in the result are gone now, how to keep the spaces?
And the "!" cannot be retained, what to do?
Last edited by xielei198210 on 2007-4-23 at 03:34 PM ]
|
|
2007-4-24 04:27 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
p处理特殊字符还是很麻烦的
Dealing with special characters in p is still quite troublesome.
|
|
2007-4-25 02:17 |
|
|
qqqrun3
初级用户
 
积分 59
发帖 28
注册 2010-11-5
状态 离线
|
『第 11 楼』:
for /F /L 带此循环
使用 LLM 解释/回答一下
『楼 主』: 用for循环进行文本替换,某些特殊字符无法替换。求助!
在批处理文件中,将文件a.txt 中的某些文字替换成别的文字
for /f "tokens=* delims= " %%i in (a.txt) do (
set n=%%i
set n=!n:aaa=bbb!
echo !n! | find /I "ECHO"
IF ERRORLEVEL 1 (
echo !n! >> temp.txt
) else (
echo. >>temp.txt
)
)
copy temp.txt a.txt
如果字串aaa中含有空格,或者点号.都不能中正确替换,有哪位大侠有更好的解决方案? 谢谢谢谢谢
TO 2楼的:
set n=!n:aaa=bbb!
将变量n中的aaa替换成bbb
@echo off & setlocal EnableDelayedExpansion
for /f "tokens=* delims=" %%i in ("Hello world.") do (
set n=%%i
set n=!n:ld.=t!
set n=!n:o w= S!
set n=!n:He=Wi!
echo !n!
)
『Thread Starter』: Using a for loop for text replacement, some special characters cannot be replaced. Need help!
In a batch file, replace some text in file a.txt with other text
for /f "tokens=* delims= " %%i in (a.txt) do (
set n=%%i
set n=!n:aaa=bbb!
echo !n! | find /I "ECHO"
IF ERRORLEVEL 1 (
echo !n! >> temp.txt
) else (
echo. >>temp.txt
)
)
copy temp.txt a.txt
If the string aaa contains spaces or dots ., it cannot be replaced correctly. Is there any great god with a better solution? Thanks thanks thanks
TO 2nd floor:
set n=!n:aaa=bbb!
Replace aaa with bbb in variable n
@echo off & setlocal EnableDelayedExpansion
for /f "tokens=* delims=" %%i in ("Hello world.") do (
set n=%%i
set n=!n:ld.=t!
set n=!n:o w= S!
set n=!n:He=Wi!
echo !n!
)
|
|
2010-12-1 23:15 |
|
|
qqqrun3
初级用户
 
积分 59
发帖 28
注册 2010-11-5
状态 离线
|
『第 12 楼』:
这样的 需dos命令扩展支持的代码的运行环境条件是什么
使用 LLM 解释/回答一下
请教前背: 这样的 setlocal EnableDelayedExpansion 需dos命令扩展支持的代码,dos7.1这样的非windows环境运行码!
Ask about the previous back: For such code that requires DOS command extensions support with setlocal EnableDelayedExpansion, can it run in a non-Windows environment like DOS 7.1?
|
|
2010-12-1 23:21 |
|