Hi there. Another noob question:
why this code:
use std::char;
fn main()
{
let c1 = char::from_digit(97, 10);
match c1 {
Some(x) => println!("{}", x),
None => (println!("Wrong way...")),
}
}
takes the wrong way?
thx.
Hi there. Another noob question:
why this code:
use std::char;
fn main()
{
let c1 = char::from_digit(97, 10);
match c1 {
Some(x) => println!("{}", x),
None => (println!("Wrong way...")),
}
}
takes the wrong way?
thx.
I think you misunderstand what char::from_digit
does. from_digit(a, b)
converts a
to a digit in base b
, e.g. from_digit(1, 10)
will give you '1'
, from_digit(10, 16)
returns 'a'
and so on. You seem to be trying to convert an ascii code to its corresponding character. char::from_u32
is probably the function you are looking for.
Ah, ok... i only read
Converts a number to the character representing it
but the following is more important
if num represents one digit under radix
thx.