strLen.cmd (477B)
1 @echo off 2 Setlocal EnableDelayedExpansion 3 :: strLen String [RtnVar] 4 :: -- String The string to be measured, surround in quotes if it contains spaces. 5 :: -- RtnVar An optional variable to be used to return the string length. 6 Set "s=#%~1" 7 Set "len=0" 8 For %%N in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( 9 if "!s:~%%N,1!" neq "" ( 10 set /a "len+=%%N" 11 set "s=!s:~%%N!" 12 ) 13 ) 14 Endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len% 15 Exit /b