replace
fn replace(Vec<byte> hay, Vec<byte> old, Vec<byte> new) -> Vec<byte> Import
Source: use bytes::{replace}; src/bytes.hy Returns a copy of hay with every non-overlapping old replaced by new, left to right.
An empty old replaces nothing.
Parameters#
| Name | Type |
|---|---|
hay | Vec<byte> |
old | Vec<byte> |
new | Vec<byte> |
Returns#
Vec<byte>
Contracts#
Checked according to --contracts (see Contracts).
ensures old.len() > 0 || eq(result, hay)
ensures old.len() == 0 || contains(hay, old) || eq(result, hay)
Examples#
use bytes::{replace, to_string};
use tests::assert;
let out = replace("a-b-c", "-", "+");
assert!((to_string(out) ?? "") == "a+b+c");
See also#
region_eq: True whena[ao..ao+n)equalsb[bo..bo+n)(caller guarantees bounds).to_hex: Encodesbufas lowercase hexadecimal, two digits per byte.from_hex: Decodes hexadecimal text (either case) into bytes.slice: Returns a copy ofsrc[start..end](end exclusive), with both offsets clamped to the buffer.concat: Returns a new buffer holdingafollowed byb.eq: Returnstruewhenaandbhave the same length and the same bytes.find_from: Returns the offset of the firstneedleinhayat or afterstart, or-1.find: Returns the offset of the firstneedleinhay, or-1.