setlocal ENABLEDELAYEDEXPANSION
for /f %%a in (1.txt) do (
set str=%%a
set str=!str:^!=@!
echo !str!
pause)
[ Last edited by HAT on 2008-12-26 at 10:45 ]
作者: HAT 时间: 2008-12-25 21:53
set /?
Environment variable substitution has been enhanced as follows:
%PATH:str1=str2%
would expand the PATH environment variable, substituting each occurrence
of "str1" in the expanded result with "str2". "str2" can be the empty
string to effectively delete all occurrences of "str1" from the expanded
output. "str1" can begin with an asterisk, in which case it will match
everything from the beginning of the expanded output to the first
occurrence of the remaining portion of str1.
认真看了一下,学了不少!
有些地方还是不太懂!!
但测试来测试去,还是不得解,这代码到底该怎么写呀?
for /f %%a in (1.txt) do (
set "str=%%a"
setlocal ENABLEDELAYEDEXPANSION
set str=!str:^!=@!
echo !str!
pause)
[ Last edited by lqh123108 on 2008-12-25 at 22:44 ]
作者: moniuming 时间: 2008-12-25 23:28
@echo off
for /f "delims=" %%a in ('more +7^<%~fs0') do (
set "str=%%a"
call set "str=%%str:!=@%%"
call echo.%%str%%
)
pause>nul&goto :eof
"真好呀!!!"
[ Last edited by moniuming on 2008-12-25 at 23:33 ]
作者: lqh123108 时间: 2008-12-26 10:43
多谢猫兄的指点
谢了
针对文件通过! OK!
for /f "delims=" %%a in (1.txt) do (
set "str=%%a"
call set "str=%%str:!=@%%"
call echo.%%str%%
)
pause>nul&goto :eof
看来,文本中的感叹号的替换不能启用变量延迟,而应该使用跳出循环的办法,防止歧义!