Advertisement
hidde663

getstringlenght.bat

Sep 13th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. ::---------------------------------------
  2. ::usage example ran from cmd.exe with stringlenght.bat either in path or the current directory:
  3. ::
  4. ::getstringlenght.bat 9223372036854775807
  5. ::
  6. ::cmd will respond with:
  7. ::
  8. ::19
  9. ::---------------------------------------
  10. @echo off&setlocal enabledelayedexpansion
  11. set "string=%~1"
  12. call :strlen ans string
  13. echo !ans!
  14. exit/b
  15. :strlen
  16. set l=0
  17. set "s=!%~2!#"
  18. for %%P in (512 256 128 64 32 16 8 4 2 1) do (
  19. if "!s:~%%P,1!" NEQ "" (
  20. set/a "l+=%%P"
  21. set "s=!s:~%%P!"
  22. )
  23. )
  24. set "%~1=%l%"
  25. exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement