Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. @echo off
  2. cls
  3. :: This is a positive integer and will return TRUE
  4. Call :isNum 54
  5. echo %retval%
  6.  
  7. :: This is a negative integer and will return TRUE
  8. Call :isNum -13
  9. echo %retval%
  10.  
  11. :: This is not an integer and will return FALSE
  12. Call :isNum 15a7
  13. echo %retval%
  14.  
  15. :: This is a decimal and will return FALSE
  16. Call :isNum 12.7
  17. echo %retval%
  18. exit /b
  19.  
  20. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  21. :: Determines if a string argument is an integer value
  22. ::
  23. :: Arguments: %1 - the string to check
  24. :: Returns: TRUE if the string is an integer, FALSE otherwise
  25. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  26. :isNum
  27. setlocal enabledelayedexpansion
  28. set num=%1
  29.  
  30. :: Strip the leading negative symbol if there is one
  31. if "!num:~0,1!"=="-" set num=!num:~1!
  32.  
  33. :: Use all digits as delimiters. If there is anything left, it's not an integer.
  34. for /f "delims=1234567890" %%A in ("%num%") do (
  35. set new_num=%%A
  36. )
  37.  
  38. set is_num=TRUE
  39. if not "!new_num!"=="" set is_num=FALSE
  40.  
  41. endlocal&set retval=%is_num%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement