I don't understand where i wrong
Code: Select all
@echo off & setlocal enabledelayedExpansion
set "st1="
For /L %%# in (1,1,4096) do set "st1=!st1!A"
call :strlen st1 len1
echo !len1!
set "st2="
For /L %%# in (1,1,4089) do set "st2=!st2!_"
call :strlen st2 len2
echo !len2!
set st3=!st1!!st2!
call :strlen st3 len3
echo !len3!
set /a l=len1+len2
echo calculate=!l!
goto :eof
: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
:: Many thanks to 'sowgtsoi', but also 'jeb' and 'amel27' dostips forum users helped making this short and efficient
:$created 20081122 :$changed 20101116 :$categories StringOperation
:$source http://www.dostips.com
( 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
result:
Code: Select all
4096
4089
8191
calculate=8185
Einstein1969