Home > other >  Converting between &str formatted like a unicode escape sequence into a char
Converting between &str formatted like a unicode escape sequence into a char

Time:02-01

Is there any way to convert a &str formatted like a unicode escape sequence into a char (ideally without using an external crate)?

e.g. "\\u{00e1}": &str -> '\u{00e1}': char

CodePudding user response:

You convert a Unicode escape sequence from a string to a character like any other ordinary character:

let s: &str = "\u{00e1}";
assert!(s.chars().next().unwrap() == '\u{00e1}');
  • Related