I want to get an individual digit from a string as int (not ascii num)
Sounds easy? - I can't do it without hacks :)
var s = "1234"
var n: int
n = int(s[0]) # nope, 49
n = parseInt(s[0]) # nope, type mismatch: got (char)i =
n = parseInt(string(s[0])) # nope, conversion from char to string is invalid
n = parseInt((s[0] & ' ').strip) # works, but not very elegant
I checked the docs, maybe I'm missing something stupidly simple... Like this for example:
import strutils
let
s = "1234"
a = int(s[0]) - int('0') # Doesn't create a string, no error
b = parseInt($s[0]) # Higher level, $ stringifies
c = parseInt(s[0..0]) # Also high level, slice of a string