macro_rules! split_inclusive {
($s: expr, $pat: expr) => { ... };
}
Expand description
Returns an array of substrings of a string slice, separated by characters matched by a pattern.
Differs from the array produced by split!
in that
split_inclusive!
leaves the matched part as the terminator of the substring.
If the last element of the string is matched, that element will be considered the terminator of the preceding substring. That substring will be the last item returned by the iterator.
The pattern type must be one of
This macro is const-context only.
See also str::split_inclusive
.
ยงExamples
const TEXT: &str = "Mary had a little lamb\nlittle lamb\nlittle lamb.";
const ANSWER:&[&str] = &const_str::split_inclusive!(TEXT, "\n");
assert_eq!(ANSWER, &["Mary had a little lamb\n", "little lamb\n", "little lamb."]);
const TEXT: &str = "\nA\nB\nC\n";
const ANSWER:&[&str] = &const_str::split_inclusive!(TEXT, "\n");
assert_eq!(ANSWER, &["\n", "A\n", "B\n", "C\n"]);