使用方法:文本编辑器编码ansi,代码复制进去保存为后缀名为bat的批处理文件,双击运行
@echo off
setlocal enabledelayedexpansion
echo 求字符串长度程序
echo.
echo 作者:phenix221
echo.
echo 邮箱:279682817@qq.com
echo.
set /p key=请输入字符:
echo.
set "key=%key:!=^^^!%"
rem set "key=!key:!=^!!"
echo !key!>%temp%\len.txt
set len=0
set "key=!key:^!=~!"
rem set "key=!key:^!=~!"
call :getLen
set strs=
for /f "tokens=*" %%a in (%temp%\len.txt) do (
set strs=%%a
)
echo !strs!长度为:!len!
echo.
pause
exit
:getLen
for /f "tokens=*" %%a in ("!key!") do (
set chars=%%a
set key=!chars:~1!
if "!key!" neq "" (
set /a len+=1
goto :getLen
) else (
set /a len+=1
)
)