Advertisement
IcarusLives

length Function

Feb 18th, 2017
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.70 KB | None | 0 0
  1. ::---------------------------------------------------------------------------------------
  2. :: Get the length of a string or number
  3. ::
  4. :: call :length "Hello World" varName
  5. :: echo %varName%
  6. ::---------------------------------------------------------------------------------------
  7. :length
  8.     setlocal
  9.         set "str=X%~1"
  10.         set length=0
  11.         for /L %%a in (8,-1,0) do (
  12.             set /a "length|=1<<%%a"
  13.             for %%b in (!length!) do if "!str:~%%b,1!" equ "" set /a "length&=~1<<%%a"
  14.         )
  15.     (endlocal
  16.         if "%~2" neq "" ( set "%2=%length%" ) else echo %length%
  17.     )
  18. goto :eof
  19. ::---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement