forked from PassingTheKnowledge/Batchography
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug-5.bat
34 lines (27 loc) · 837 Bytes
/
debug-5.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@echo off
setlocal enabledelayedexpansion
@if NOT DEFINED _CNDECHO (set _CNDECHO=^>NUL)
:main
setlocal
set /P str=Enter string:
echo DBG: the string value is %str% %_CNDECHO%
call :strlen "%str%"
echo length=%errorlevel%
goto :eof
:strlen <1=string> => errorlevel
set "s=%~1."
echo DBG: inside str-len, initial value is ^<%s%^> %_CNDECHO%
set len=0
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
echo DBG: P=%%P str part is ^<!s:~%%P,1!^> %_CNDECHO%
if "!s:~%%P,1!" NEQ "" (
set /a "len+=%%P"
echo DBG: string length so far: !len! %_CNDECHO%
set "s=!s:~%%P!"
echo DBG: truncated string so far is: !s! %_CNDECHO%
)
)
(
endlocal
exit /b %len%
)