Advertisement
GlobalAccessSoftware

string_length.bat

Nov 16th, 2023
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.77 KB | Software | 0 0
  1.  
  2.  
  3. :::::::::::::::::::::::::::::::::::::::::::
  4. ::: string_length.bat Special Function  :::
  5. :::::::::::::::::::::::::::::::::::::::::::
  6. ::: An extremely cool function found on :::
  7. ::: StackExchange and I wish I'd gotten :::
  8. ::: the contributors name and followed. :::
  9. ::: Split out from runtime_display.bat  :::
  10. ::: v7.9.8.92 20221125101121  by -JpE-  :::
  11. :::::::::::::::::::::::::::::::::::::::::::
  12.  
  13. ::: RC5
  14. ::: Special Function Finds String Length
  15. :strlen <resultVar, stringVar>
  16. (
  17.   setlocal EnableDelayedExpansion
  18.   set "s=!%~2!#"
  19.   set "len=0"
  20.   for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  21.     if "!s:~%%P,1!" NEQ "" (
  22.       set /a "len+=%%P"
  23.       set "s=!s:~%%P!"
  24.     )
  25.   )
  26. )
  27. (
  28.   endlocal
  29.   set "%~1=%len%"
  30.   exit /b %ERRORLEVEL%
  31. )
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement