Replace

Function Replace 

Source
pub fn Replace(
    s: impl AsRef<[byte]>,
    old: impl AsRef<[byte]>,
    new: impl AsRef<[byte]>,
    n: int,
) -> Vec<byte> 
Expand description

Replace returns a copy of the slice s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the slice and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune slice. If n = -1, there is no limit on the number of replacements.

zh-cn 返回将s中前n个不重叠old切片序列都替换为new的新的切片拷贝,如果n=-1会替换所有old子切片。

§Example

use gostd_bytes as bytes;

assert_eq!("oinky oinky oink".as_bytes(),bytes::Replace("oink oink oink".as_bytes(), "k".as_bytes(), "ky".as_bytes(), 2));
assert_eq!("moo moo moo".as_bytes(),bytes::Replace("oink oink oink".as_bytes(), "oink", "moo", -1));