关于替换特殊字符串的疑问!
例如文本文件test.txt内容如下:
"you are my super star!"
"you are :my super star!"
"you are my super star!"
如何将文本文件内容变成
you are my(not you) super star!
you are my(not you) super star!
you are my(not you) super star!- @echo off
- echo "you are my super star!">test.txt
- echo "you are :my super star!">>test.txt
- echo "you are my super star!">>test.txt
- echo.
- @echo off
- ::去引号
- setlocal EnableDelayedExpansion
- for /f "tokens=* delims=" %%i in (test.txt) do (
- set var=%%i
- set var=!var:"=!
- echo !var!>>ls.txt
-
- )
- pause
- echo.
- @echo off
- ::去冒号
- setlocal EnableDelayedExpansion
- for /f "tokens=* delims=" %%i in (ls.txt) do (
- set var=%%i
- set var=!var::=!
- echo !var!>>ls1.txt
-
- )
- pause
- echo.
- ::把my替换为my (not you)
- @echo off
- setlocal EnableDelayedExpansion
- for /f "tokens=* delims=" %%i in (ls1.txt) do (
- set var=%%i
- set var=!var:my=my (not you)!
- echo !var!
-
- )
- echo.
- pause
复制代码 前两个都可以正常执行,但是第三个不能执行;
我估计应该是do后面的左括号遇到not you后面的右括号就终止了;
请高手指点怎么来实现被替换的字符为包含有小括号的情况!
当然可能还会有其他特殊字符不能按照正常的替换方式替换,请给出解决方案!谢谢
呵呵,后来我想用变量来替换- @echo off
- setlocal EnableDelayedExpansion
- set /p temp=my (not you)
- for /f "tokens=* delims=" %%i in (ls1.txt) do (
- set var=%%i
- set var=!var:my=!temp!!
- ::set var=!var:my=%temp%! 貌似这样也不可以!
- echo !var!
-
- )
- echo.
- pause
复制代码 希望各位高手指点O(∩_∩)O哈!
pause
[ 本帖最后由 jackelijie135 于 2009-3-17 20:37 编辑 ] |