Advertisement
npocmaka

String length

Jan 20th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. :strlen [%1 -string, %2 variable to store result in]
  2. setlocal
  3. set string=%~1
  4. rem if the string contains double quotes it will harm the IF checks
  5. set string=%string:"=.%
  6. set var=%~2
  7. set /a counter=0
  8. if "%string%" equ "" goto :return
  9. :loop
  10.     rem counter will hold the 1/2 of the string lenght
  11.     set /a counter=%counter%+1
  12.     set string=%string:~1,-1%
  13.     if "%string%" equ "" (
  14.         goto :endloop
  15.     )
  16.  
  17. goto :loop
  18. :endloop
  19.  
  20. set string=%~1
  21. set string=%string:"=.%
  22.  
  23. set /a counter=2*%counter%-1
  24. rem checking  if the string is with even or with uneven lenght
  25. call set string=%%string:~%counter%%%
  26. if "%string%" neq "" set /a counter=%counter%+1
  27. echo %counter%
  28. :return
  29. endlocal & set %var%=%counter% >nul  2>&1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement