To go the other way (string to int) is a proc called parseInt(). To make it a 
bit more robust: 
    
    
    #
    # str2int([string], [default result])
    #
    #  . [default result] is an optional return value if parseInt() has an 
exception
    #    If not default result and exception then return 0
    #
    #  Ex.
    #    str2int("1984") == > 1984
    #    str2int("", 5) == > 5
    #    str2int("") == > 0
    #
    proc str2int*(s: string, d: varargs[int]): int =
      result = try: parseInt(s) except ValueError:
        if len(d) > 0: d[0] else: 0
    
    
    Run

Reply via email to