6 个版本
| 0.3.3 | 2023 年 12 月 3 日 |
|---|---|
| 0.3.2 | 2022 年 4 月 17 日 |
| 0.3.1 |
|
| 0.2.1 | 2022 年 1 月 8 日 |
| 0.1.0 | 2021 年 10 月 19 日 |
#458 in 文本处理
102 每月下载
用于 2 crates
6KB
69 代码行
slicestring
slicestring 是一个用于切片字符串的 crate。它为 slice() 方法提供了 String 和 &str。它接受一个 std::ops::Range 作为参数。它切片 String 或 &str 并返回切片后的 String。
示例
use slicestring::Slice;
let mut s = "hello world!";
s = s.slice(..5);
assert_eq!("hello", s);
它也适用于表情符号,因为 slice 方法考虑了字符。
use slicestring::Slice;
let mut s = String::from("hello 😃");
s = s.slice(5..);
assert_eq!("😃", s);
lib.rs:
slicestring 是一个用于切片字符串的 crate。它为 slice() 方法提供了 String 和 &str。它接受索引范围作为参数,其中第二个索引也可以传递负值。它切片 String 或 &str 并返回切片后的 String。
示例
use slicestring::Slice;
let mut s = "hello world!";
s = s.slice(..5);
assert_eq!("hello", s);
它也适用于表情符号,因为 slice() 方法考虑了字符。
let mut s = String::from("hello 😃");
s = s.slice(5..);
assert_eq!("😃", s);