Данный код поможет решить задачу по подсчёту количества символов в случайной строке:
********************************************************************************
@echo off
set my_string=This is my string!
call :strlen result my_string
echo %my_string%
echo strlen %result%
pause
goto :eof
:strlen
(
setlocal EnableDelayedExpansion
set "s=!%~2!#"
set "len=0"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "s=!s:~%%P!"
)
)
)
(
endlocal
set "%~1=%len%"
exit /b
)
********************************************************************************
********************************************************************************
@echo off
set my_string=This is my string!
call :strlen result my_string
echo %my_string%
echo strlen %result%
pause
goto :eof
:strlen
(
setlocal EnableDelayedExpansion
set "s=!%~2!#"
set "len=0"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "s=!s:~%%P!"
)
)
)
(
endlocal
set "%~1=%len%"
exit /b
)
********************************************************************************
Комментариев нет:
Отправить комментарий