本帖最后由 fzp070 于 2022-10-14 20:52 编辑
如下方法也可以试试,不过还有缺陷,如字符中有3个及以上!号时会丢失字符。
awa.txt内容为:复制代码 代码为:- @echo off
- setlocal enabledelayedexpansion
- set /p pp=<awa.txt
- echo;"!pp!"
-
-
- ::本次去除!号
- :Loop1
- for /f "tokens=1* delims=!" %%a in ("!pp!") do set "pp=%%a%%b"
- echo,"!pp!"|findstr "[!]">nul&&goto :Loop1
- echo,"!pp!"
-
-
- ::本次去除*号
- :Loop2
- for /f "tokens=1* delims=*" %%a in ("!pp!") do set "pp=%%a%%b"
- echo,"!pp!"|findstr "[*]">nul&&goto :Loop2
- echo,"!pp!"
-
-
- ::本次去除%号
- :Loop3
- for /f "tokens=1* delims=%%" %%a in ("!pp!") do set "pp=%%a%%b"
- echo,"!pp!"|findstr "[%]">nul&&goto :Loop3
- echo,"!pp!"
-
-
- ::本次去除?号
- :Loop4
- for /f "tokens=1* delims=?" %%a in ("!pp!") do set "pp=%%a%%b"
- echo,"!pp!"|findstr "[?]">nul&&goto :Loop4
- echo,"!pp!"
-
-
- ::本次去除=号
- :Loop5
- for /f "tokens=1* delims==" %%a in ("!pp!") do set "pp=%%a%%b"
- echo,"!pp!"|findstr "[=]">nul&&goto :Loop5
- echo,"!pp!"
-
-
- ::本次去除@号
- :Loop6
- for /f "tokens=1* delims=@" %%a in ("!pp!") do set "pp=%%a%%b"
- echo,"!pp!"|findstr "[@]">nul&&goto :Loop6
- echo,"!pp!"
-
- pause
复制代码 结果为:- "123@%*!456?=7!89"
- "123@%*456?=789"
- "123@%456?=789"
- "123@456?=789"
- "123@456=789"
- "123@456789"
- "123456789"
- 请按任意键继续. . .
复制代码
|