📜  rust 获取字符串中的第 n 个字符 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:22.404000             🧑  作者: Mango

代码示例1
If you want just the first char, then don't collect into a Vec, just use the iterator:

let text = "hello world!";
let ch = text.chars().next().unwrap();

Alternatively, you can use the iterator's nth method:

let ch = text.chars().nth(0).unwrap();