本帖最后由 zm900612 于 2011-5-18 23:18 编辑
用变量替换+for实现精确定位字符串...- @echo off&setlocal enabledelayedexpansion
- for %%1 in (*.txt) do (
- (for /f "delims=" %%2 in (%%~s1) do (
- set str=%%2 @
- for %%A in ("a=shoes" "the=cloth") do (
- set tmp=!str!&set str=
- for /f "tokens=1* delims==" %%B in ("%%~A") do (
- for /l %%D in (1 1 10) do (
- if defined tmp (
- if "!tmp: %%B =!" neq "!tmp!" (
- for /f "tokens=1*" %%a in ("!tmp:* %%B =!") do (
- set str=!str!!tmp:%%a %%b=!%%C
- if "%%b"=="" set str=!str:~0,-6!
- set tmp= %%b
- )
- rem 核心代码,利用tokens+变量通配替换,准确定位所有目标字符串的位置。其他部分太琐碎,我不知道该怎么解释...
- ) else if %%D==10 set str=!str!!tmp!
- )
- )
- )
- )
- echo !str:~0,-2!
- ))>$
- move $ "%%1"
- )>nul
- pause
复制代码 写完才发现似乎绕弯子了 |