3 个不稳定版本
0.2.0 | 2019年5月25日 |
---|---|
0.1.1 | 2017年7月23日 |
0.1.0 | 2017年7月23日 |
#1440 in 文本处理
4KB
60 行
trim_lines
注意:此 crate 已 弃用。您应该使用 map(str::trim)
代替
fn main() {
let text = " foo \r\n bar \n \n baz \n";
let mut lines = text.lines().map(str::trim);
assert_eq!(Some("foo"), lines.next());
assert_eq!(Some("bar"), lines.next());
assert_eq!(Some(""), lines.next());
assert_eq!(Some("baz"), lines.next());
assert_eq!(None, lines.next());
}
一个非常简单且体积很小的库,它提供对字符串行进行迭代的功能,并移除了空白字符。它是对 std::str 中的 Lines 迭代器的一个简单封装,从每行中移除空白字符。