第二题代码如下:- @echo off
- setlocal enabledelayedexpansion
- set/p var1=请输入要查找的内容:
- set/p var2=请输入要替换的内容:
- :len
- if not "!var1:~%num1%,1!"=="" (set/a num1+=1&goto :len)
- for /f "delims=" %%a in (a.txt) do (
- set str=%%a
- set/a num+=1
- call :replace !str! !num1!
- )
- pause
- goto :eof
-
- :replace
- set ss=%1
- set/a n=0
- :a
- set/a m=%n%+%2
- if not "!ss:~%n%,1!"=="" (
- if "!ss:~%n%,%2!"=="!var1!" (
- set ss=!ss:~0,%n%!!var2!!ss:~%m%!
- set/a n+=1
- goto :a
- ) else (set/a n+=1&goto:a)
- ) else (echo !ss!>>aa.txt)
复制代码
[ 本帖最后由 sjzong 于 2009-4-24 11:47 编辑 ] |