Split

Function Split 

Source
pub fn Split(s: impl AsRef<[byte]>, sep: impl AsRef<[byte]>) -> Vec<Vec<byte>>
Expand description

Split slices s into all subslices separated by sep and returns a slice of the subslices between those separators. If sep is empty, Split splits after each UTF-8 sequence. It is equivalent to SplitN with a count of -1.

zh-cn 用去掉s中出现的sep的方式进行分割,会分割到结尾,并返回生成的所有&[byte]切片组成的切片(每一个sep都会进行一次切割,即使两个sep相邻,也会进行两次切割)。如果sep为空字符,Split会将s切分成每一个unicode码值一个[]byte切片。

§Example

use gostd_bytes as bytes;

assert_eq!(vec![b"a".to_vec(),b"b".to_vec(),b"c".to_vec()],bytes::Split("a,b,c".as_bytes(),b","));
assert_eq!(vec![b"".to_vec(),b"man ".to_vec(),b"plan ".to_vec(),b"canal panama".to_vec()],bytes::Split("a man a plan a canal panama".as_bytes(),b"a "));
assert_eq!(vec![b" ".to_vec(), b"x".to_vec(), b"y".to_vec(), b"z".to_vec(), b" ".to_vec()],bytes::Split(" xyz ".as_bytes(),""));
assert_eq!(vec![b"".to_vec()],bytes::Split("".as_bytes(),"Bernardo O'Higgins".as_bytes()));