|
|
发表于 2025-7-31 10:09:09
|
显示全部楼层
批处理的特殊字符恶心死了
变量替换功能的*号是通配符 ,无法作为普通字符; =号是界定符 ,但是无法界定自身并作为普通字符; 而~号在这之前就被解释成变量截取功能了...
变量长度不长 ,最好还是逐字符截取并判断处理
- @echo off
- set z=!A B^"C,D.E/F:G?H\I^|J^<K^>L*M-N
- set replace=set "s=!s!_"^&set "x="
- setlocal enabledelayedexpansion
- for /l %%l in (0,1,32) do (
- set x=!z:~%%l,1!
- if "!x!" == "~" %replace%
- if "!x!" == "`" %replace%
- if "!x!" == "^!" %replace%
- if "!x!" == "%%" %replace%
- if "!x!" == "^" %replace%
- if "!x!" == "&" %replace%
- if "!x!" == "*" %replace%
- if "!x!" == "<" %replace%
- if "!x!" == ">" %replace%
- if "!x!" == "?" %replace%
- if "!x!" == ":" %replace%
- if "!x!" == "|" %replace%
- if "!x!" == ^"^"^" %replace%
- if "!x!" == "" %replace%
- if "!x!" == "/" %replace%
- if "!x!" == "," %replace%
- if "!x!" == " " %replace%
- if "!x!" neq "" set "s=!s!!x!"
- )
- echo,!z! [before]
- echo,!s! [after]
- endlocal&pause&exit /b 0
复制代码 |
评分
-
查看全部评分
|