第一个太简单了:
@echo off
set /p "str=输入字符串:"
call:Length "%str%" "l"
echo 长度是:%l%。
pause>nul
exit /b 0
:Length
setlocal enabledelayedexpansion&set /a "_len_=-1"
set "__str=%~1"
:__Len_FUNCTION
set /a "_len_+=1"
for /f %%i in ("%_len_%") do if not "!__str:~%%i,1!"=="" goto :__Len_FUNCTION
Endlocal&set "%~2=%_len_%"&goto :EOF
@echo off
set /p "str=输入字符串:"
call:Length "%str%" "l"
echo 长度是:%l%。
pause>nul
exit /b 0
:Length
setlocal enabledelayedexpansion&set /a "_len_=-1"
set "__str=%~1"
:__Len_FUNCTION
set /a "_len_+=1"
for /f %%i in ("%_len_%") do if not "!__str:~%%i,1!"=="" goto :__Len_FUNCTION
Endlocal&set "%~2=%_len_%"&goto :EOF