本帖最后由 0000 于 2017-1-13 15:05 编辑
感谢pusofalse关于第三段中效率问题的建议,我运行了一下,效率可以提高很多,但是字母输出却全为大写字母,原因为此句 If defined .!var! 中对于.!var!的判断,小写字母和大写字母在此不区分。 - @echo off
- setlocal ENABLEDELAYEDEXPANSION
- rem 标记大写字母
- set CAP=ABCDEFGHIJKLMNOPQRSTUVWXYZ
- for /l %%n in (0,1,25) do (set CAP_!CAP:~%%n,1!=!CAP:~%%n,1!)
-
- echo 大小写字母分类器
- set /p lts=要分类的字母:
- set cap=
- set notcap=
- set other=
- :fenlei
- if "!lts!"=="" goto ok
- set lt=!lts:~0,1!
- set lts=!lts:~1!
- if "!lt!"=="!" set other=!other!^^!
- if "!lt!"=="=" set other=!other!=
- if "!lt!"==":" set other=!other!:
- if "!CAP_%lt%!"=="" (
- set other=!other!!lt!
- goto fenlei
- )
- if "!CAP_%lt%!"=="!lt!" (
- set cap=!cap!!lt!
- ) else (
- set notcap=!notcap!!lt!
- )
- goto fenlei
- :ok
- echo 大写字母有:!cap!
- echo 小写字母有:!notcap!
- echo 不是字母的有:!other!
- pause
复制代码
|