An easier way to convert a character to an integer?

You still feel like Julia’s standard library. I can convert strings to their integer representation via int () function, but when I call int () with char, I get an integer value corresponding to the character. Currently, I am calling string () first:

intval = int(string(c)) 

Is this a common way to do this? Or is there a more standard method? This had a very good effect on my Project Euler exercise.

+7
julia-lang
source share
1 answer

You can use parse(Int, c) , which will be much more efficient. The reason int(c) does not do what you want is that it gives the Unicode code point of the character c , rather than interpreting it as a digit. It would be nice if they corresponded, but they do not. This makes me wonder if int(s) good idea for string s , since it does not meet the requirements of int(c) .

+14
source share

All Articles