std-method

Integer from_str_radix

Convert text in a chosen base (2 through 36). Remove a representation prefix explicitly if your input format permits it. Expected stdout (not executed): Ok(255) true true Common mistake: Passing an invalid radix can panic; validating the text alone is insufficient.

Formal Syntax & Structure

rust syntaxrust
u8::from_str_radix(text, radix) -> Result<u8, ParseIntError>

Working Example

Example Snippetrust
fn main() {    println!("{:?}", u8::from_str_radix("ff", 16));    println!("{}", u8::from_str_radix("100", 16).is_err());    println!("{}", u8::from_str_radix("0xff", 16).is_err());}
Rust Reference