let mut start = true;
for v in count as String {
s += match v as usize {
n if n == 2 || n == 3 => "\u{00b" + n + "}",
n if n >= 4 || (n <= 1 && !start) => "\u{207" + n + "}",
start && 1 => "",
}
start = false;
}
我知道这不是编写Unicode字符的预期方法:
error: unterminated unicode escape (needed a `}`)
--> src/main.rs:5:45
|
5 | n if n == 2 || n == 3 => "\u{00b" + n + "}",
| ^
但是正确的方法是什么?
答案 0 :(得分:0)
结合std::char::from_u32
和String::push
:
use std::char::from_u32;
let mut s = String::new();
s.push(from_u32(0xb0 + 2).unwrap());
s.push(from_u32(0xb0 + 3).unwrap());
s.push(from_u32(0x2070 + 1).unwrap());
println!("{:?}", s);