小编Keh*_*eho的帖子

拆分保持分隔符的字符串

是否有一种简单的方法来分割保持分隔符的字符串?而不是这个:

let texte = "Ten. Million. Questions. Let's celebrate all we've done together.";
let v: Vec<&str> = texte.split(|c: char| !(c.is_alphanumeric() || c == '\'')).filter(|s| !s.is_empty()).collect();
Run Code Online (Sandbox Code Playgroud)

结果如何["Ten", "Million", "Questions", "Let's", "celebrate", "all", "we've", "done", "together"].

我想要一些能给我的东西:

["Ten", ".", " ", "Million", ".", " ", "Questions", ".", " ", "Let's", " ", "celebrate", " ", "all", " ", "we've", " ", "done", " ", "together", "."].

我正在尝试这种代码(它假设字符串以字母开头,以'非'字母结尾):

let texte = "Ten. Million. Questions. Let's celebrate all we've done together. …
Run Code Online (Sandbox Code Playgroud)

rust

10
推荐指数
3
解决办法
1171
查看次数

标签 统计

rust ×1