楼上这样会漏字。
1:- @echo off&setlocal enabledelayedexpansion
- (for /f "delims=" %%i in (a.txt) do (
- set tmp=%%i
- set /a 总是=0,特征=0
- for /l %%a in (0 1 1000) do (
- if !总是!==0 set /p=!tmp:~%%a,1!<nul
- if "!tmp:~%%a,2!"=="总是" set 总是=1&set /p=是<nul
- if "!tmp:~%%a,2!"=="特征" (
- if !总是!==1 set /p=!tmp:~%%a,1!<nul
- set 总是=0
- )
- )
- echo;
- ))>b.txt
- pause
复制代码 2:- @echo off&setlocal enabledelayedexpansion
- (for /f "delims=" %%i in (a.txt) do (
- set tmp=%%i
- set /a 总是=0,特征=0
- for /l %%a in (0 1 1000) do (
- set /a "特征-=^!^!特征"
- if "!tmp:~%%a,2!"=="总是" set 总是=1
- if "!tmp:~%%a,2!"=="特征" (
- set /a 总是=0,特征=2
- )
- if !总是!==0 if !特征!==0 set /p=!tmp:~%%a,1!<nul
- )
- echo;
- ))>b.txt
- pause
复制代码 3:- @echo off&setlocal enabledelayedexpansion
- (for /f "delims=" %%i in (a.txt) do (
- set tmp=%%i
- set "tmp=!tmp:总是=!"&set "tmp=!tmp:特征=!"
- for %%a in ("!tmp!") do echo %%~a
- ))>b.txt
- pause
- ::效率高,但是遇到特殊字符可能出错
复制代码
- @echo off &setlocal enabledelayedexpansion
- (for /f "delims=" %%i in (a.txt) do (
- set tmp=%%i
- set /a 总是=0,特征=0
- for /l %%a in (0 1 1000) do (
- set /a "总是-=^!^!总是","特征-=^!^!特征"
- if "!tmp:~%%a,2!"=="总是" set 总是=2
- if "!tmp:~%%a,2!"=="特征" set 特征=2
- if !总是!==0 if !特征!==0 set /p "m=!tmp:~%%a,1!"<nul
- )
- echo;
- ))2>nul
- pause
- ::效率低,但是保险
复制代码
|