Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :strlen [%1 -string, %2 variable to store result in]
- setlocal
- set string=%~1
- rem if the string contains double quotes it will harm the IF checks
- set string=%string:"=.%
- set var=%~2
- set /a counter=0
- if "%string%" equ "" goto :return
- :loop
- rem counter will hold the 1/2 of the string lenght
- set /a counter=%counter%+1
- set string=%string:~1,-1%
- if "%string%" equ "" (
- goto :endloop
- )
- goto :loop
- :endloop
- set string=%~1
- set string=%string:"=.%
- set /a counter=2*%counter%-1
- rem checking if the string is with even or with uneven lenght
- call set string=%%string:~%counter%%%
- if "%string%" neq "" set /a counter=%counter%+1
- echo %counter%
- :return
- endlocal & set %var%=%counter% >nul 2>&1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement