[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
先看看高手如何做自己再研究下丶

TOP

看看7楼的答案,暂时不潜水

TOP

@echo off
setlocal enabledelayedexpansion
for /f %%b in (a.txt) do (
set dd=%%b
set bb=!dd:他娘的=tnd!
echo !bb!
)
pause>nul
蚂蚁dos

TOP

写了了遍 还真发现错的地方 

写=的时候没关输入法 结果查错 查了半天
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in (a.txt) do (
  3.     set a=%%i
  4.     set b=!a:他娘的=TND!
  5.     echo !b!
  6. )
  7. for /f "delims=" %%j in (a.txt) do (
  8.     set c=%%j
  9.     set d=!c:他娘的=!
  10.     echo !d!
  11. )
  12. pause
复制代码

TOP

呵呵,其实我是看了8楼的方法,再改了一点就得出了楼主的第二个题目的答案了

::A1
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.txt) do (
    set var=%%a
    set change=!var:他娘的=TND!
    echo !change!
)
pause>nul

::A2
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (a.txt) do (
    set var=%%a
    set change=!var:他娘的=!
    echo !change!
)
pause>nul

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f %%i in (test.txt) do (
  4. set str=%%i
  5. echo !str:他娘的=TND!
  6. )
  7. pause
  8. for /f %%i in (test.txt) do (
  9. set str=%%i
  10. echo !str:他娘的=!
  11. )
  12. pause
复制代码
扬鞭策马自奋蹄!

TOP

  1. @echo off
  2. setlocal
  3. setlocal enabledelayedexpansion
  4. for "tokens=*" /f %%f in (a.txt) do (
  5.   set strtmp=%%f
  6.   set strtmp=!strtmp:他娘的=TND!
  7.   echo !strtmp!
  8. )
  9. endlocal
复制代码
我是一只小菜鸟,飞到东来飞到西……

TOP

不用变量延时也能做到

  1. @echo off
  2. set /p str=<1.txt
  3. set str1=%str:他娘的=TND%
  4. set str2=%str1:TND=%
  5. echo %str% &echo.
  6. echo %str1% &echo.
  7. echo %str2% &echo.
  8. pause
复制代码

TOP

如下
@ECHO OFF
SET VARa=你他娘的是谁?他娘的我不告诉你。你他娘的到底是谁?我他娘的还就不告诉那个他娘的你。
SET VARb=%VARa:他娘的=TND%
ECHO 替换后的值:%VARb%
pause

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. echo 流氓对话:
  4. type a.txt
  5. echo.
  6. echo 网络对话:
  7. pause>nul
  8. for /f %%a in (a.txt) do (
  9. set str=%%a
  10. set newstr=!str:他娘的=TND!
  11. echo !newstr!
  12. )
  13. echo.
  14. echo 文明对话:
  15. pause>nul
  16. for /f %%a in (a.txt) do (
  17. set str=%%a
  18. set newstr=!str:他娘的=!
  19. echo !newstr!
  20. )
  21. echo    按任意键退出!
  22. pause>nul
复制代码

TOP

换成“TND”输出:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f %%a in (a.txt) do (
  4.   set int=%%a
  5.   set yu=!int:他娘的=TND!
  6.   echo !yu!
  7. )
  8. pause>nul
复制代码
去掉“他娘的”输出:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f %%a in (a.txt) do (
  4.   set int=%%a
  5.   set yu=!int:他娘的=!
  6.   echo !yu!
  7. )
  8. pause>nul
复制代码

TOP

  1. @echo off
  2. set str=你他娘的是谁?他娘的我不告诉你。你他娘的到底是谁?我他娘的还就不告诉那个他娘的你。
  3. echo  %str:他娘的=TND%
  4. echo %str:他娘的=%
  5. pause
复制代码


学习了for,重新写
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "tokens=*" %%i in (a.txt) do (
  4.     set a=%%i
  5.     set a=!a:他娘的=TND!
  6.     echo !a!
  7. )
  8. for /f "tokens=*" %%i in (a.txt) do (
  9.     set a=%%i
  10.     set a=!a:他娘的=!
  11.     echo !a!
  12. )
  13. pause
复制代码

[ 本帖最后由 zgq0301 于 2009-11-13 19:48 编辑 ]

TOP

第二个目的 用一条语句就可以解决,不用P处理

for /f "delims=他娘的 tokens=1,2,3,4,5" %c in (123.txt) do @echo %c%d%e%f%g

TOP

  1. @echo off & setlocal EnableDelayedExpansion
  2. echo 你他娘的是谁?他娘的我不告诉你。你他娘的到底是谁?我他娘的还就不告诉那个他娘的你
  3. pause>nul
  4. echo.
  5. set n="你他娘的是谁?他娘的我不告诉你。你他娘的到底是谁?我他娘的还就不告诉那个他娘的你。"
  6. for /f  "tokens=* delims=" %%i in (%n%) do (
  7.     set a=%%i
  8.     set a=!a:他娘的=TND!
  9.     echo !a!
  10. )
  11. pause>nul
  12. echo.
  13. echo.
  14. set b="%a%"
  15. for /f "tokens=* delims=" %%a in (%b%)do (
  16.     set b=%%a
  17.     set b=!b:TND=!
  18.     echo !b!
  19. )
  20. pause>nul
复制代码
说句话,变量延迟真TMD难理解(— —)

TOP

for /f "tokens=*" %%i in (a.txt) do (
    set a=%%i
    set a=!a:他娘的=!
    echo !a!
set a=!a:他娘的=!这一句是什么意思啊??为什么要用!!

TOP

返回列表