From anonymous, 6 Years ago, written in Python.
Embed
  1. def dint(str, default):
  2.         try:
  3.                 return int(str)
  4.         except ValueError:
  5.                 return default
  6.  
  7. print(dint('a', 10)) # 10
  8. print(dint('9', 10)) # 9
  9. print(dint('9', 10))