我一直在尝试用它在字母表中的位置替换给定字符串片中的每个字母("A“用"1","B”用"2“等等)。
fn alphabet_position(text: &str) -> String {
let s = text
.chars()
.into_iter()
.filter(|&c| c.is_alphabetic())
.map(|c| c.to_ascii_uppercase())
.map(|c| c as u8)
.map(|c| (c - 64u8) as char)
.collect();
s
}发布于 2021-03-11 13:31:00
尝试使用u8::to_string()函数。
fn alphabet_position(text: &str) -> String {
let s = text
.chars()
.into_iter()
.filter(|&c| c.is_alphabetic())
.map(|c| c.to_ascii_uppercase())
.map(|c| c as u8)
.map(|c| (c - 64u8).to_string())
.collect();
s
}https://stackoverflow.com/questions/66576556
复制相似问题