Created
September 1, 2011 03:41
-
-
Save ijprest/1185398 to your computer and use it in GitHub Desktop.
CMD Batch file implementation of strlen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION | |
call :strlen "%~1" | |
echo strlen("%~1") == !ERRORLEVEL! | |
goto :EOF | |
:strlen | |
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION | |
set __LEN=0 | |
set __LEN_S=%~1 | |
:strlen_loop | |
if "!__LEN_S!"=="" exit /B %__LEN% | |
for %%Q IN (32 16 8 4 2) DO if NOT "!__LEN_S:~%%Q!"=="" set /A __LEN=!__LEN!+%%Q&set __LEN_S=!__LEN_S:~%%Q!&goto :strlen_loop | |
set /A __LEN=!__LEN!+1&set __LEN_S=!__LEN_S:~1!&goto :strlen_loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be relatively efficient (as these things go) because it tries to break off 32-character chunks at a time, instead of doing it character by character.