home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 13 / getlngth.bat < prev    next >
DOS Batch File  |  1992-01-16  |  936b  |  31 lines

  1. @ECHO OFF
  2. Rem  ### Get the length of Environment Variable STRING,   ###
  3. Rem  ### set to the value of %1 on entry. Set the length  ###
  4. Rem  ### in Environment Variable LENGTH. Lengths greater  ###
  5. Rem  ### than nine characters set LENGTH equal to 9+.     ###
  6. Rem  ### Variable STRING may not include the ~ character. ###
  7. SET string=%1
  8. IF '%string%'=='' GOTO zero
  9. SET temp=%string%~
  10. SET length=
  11. :loop
  12. SET length=+%length%
  13. FOR %%y IN (/%temp%) DO SET temp=%%y
  14. IF NOT %temp%==~ GOTO loop
  15. IF %length%==+ SET length=1
  16. IF %length%==++ SET length=2
  17. IF %length%==+++ SET length=3
  18. IF %length%==++++ SET length=4
  19. IF %length%==+++++ SET length=5
  20. IF %length%==++++++ SET length=6
  21. IF %length%==+++++++ SET length=7
  22. IF %length%==++++++++ SET length=8
  23. IF %length%==+++++++++ SET length=9
  24. FOR %%z IN (/%length%) do if %%z==+ SET length=9+
  25. GOTO done
  26. :zero
  27. SET length=0
  28. :done
  29. SET temp=
  30. ECHO Length of "%string%" is %length%
  31.