简体   繁体   中英

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

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

eg "\\u{00e1}": &str -> '\u{00e1}': char

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}');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM