Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for reversent.bat

(view source code of reversent.bat as plain text)

  1. @ECHO OFF
  2. :: Keep variables local
  3. SETLOCAL
  4.  
  5. :: Check command line parameters
  6. IF [%1]==[] GOTO Syntax
  7. ECHO.%* | FIND "=" >NUL
  8. IF NOT ERRORLEVEL 1 GOTO Syntax
  9.  
  10. :: Initialize variables
  11. SET REVERSE=
  12. SET INPUT=%*
  13. :: Strip leading space in NT 4 only
  14. VER | FIND "Windows NT" >NUL
  15. IF NOT ERRORLEVEL 1 SET INPUT=%INPUT:~1%
  16.  
  17. :Loop
  18. :: Continue till the input string's last character
  19. IF NOT DEFINED INPUT GOTO Finish
  20. :: Separate first character from input string
  21. SET FIRSTCHAR=%INPUT:~0,1%
  22. SET INPUT=%INPUT:~1%
  23. :: Rebuild string in reverse order
  24. SET REVERSE=%FIRSTCHAR%%REVERSE%
  25. :: Next character
  26. GOTO Loop
  27.  
  28. :Finish
  29. ECHO.
  30. :: Add leading space for Windows 2000 and later
  31. VER | FIND "Windows NT" >NUL
  32. IF ERRORLEVEL 1 (ECHO Input string   = %*) ELSE (ECHO Input string   =%*)
  33. ECHO Reverse string = %REVERSE%
  34. GOTO End
  35.  
  36. :Syntax
  37. ECHO.
  38. ECHO REVERSE.BAT,  Version 2.00 for Windows NT 4 / 2000
  39. ECHO Reverses the input string specified on the command line
  40. ECHO Written by Rob van der Woude
  41. ECHO http://www.robvanderwoude.com
  42. ECHO.
  43. ECHO Usage:  REVERSE ^<string^>
  44. ECHO.
  45. ECHO ^<string^> cannot contain equal signs ("=")
  46. ECHO.
  47. ECHO Example:
  48. ECHO REVERSE Any string
  49. ECHO.
  50. ECHO returns:
  51. ECHO Input string   = Any string
  52. ECHO Reverse string = gnirts ynA
  53.  
  54. :End
  55. ENDLOCAL
  56.  

page last modified: 2024-02-26; loaded in 0.0181 seconds