:strLen string len -- returns the length of a string :: -- string [in] - variable name containing the string being measured for length :: -- len [out] - variable to be used to return the string length ( SETLOCAL ENABLEDELAYEDEXPANSION set "str=A!%~1!"&rem keep the A up front to ensure we get the length and not the upper bound rem it also avoids trouble in case of empty string set "len=0" for /L %%A in (12,-1,0) do ( set /a "len|=1<<%%A" for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A" ) ) ( ENDLOCAL & REM RETURN VALUES IF "%~2" NEQ "" SET /a %~2=%len% ) EXIT /b