bytes
Functions
clone
clone(b byte_slice) byte_sliceClone returns a new byte slice containing the same bytes as the given byte slice.
>>> bytes.clone(byte_slice([1, 2, 3, 4]))
byte_slice("\x01\x02\x03\x04")contains_any
contains_any(b byte_slice, chars string) boolReports whether any of the UTF-8-encoded code points in the string are present in the byte_slice.
>>> bytes.contains_any(byte_slice("Hello"), "abco")
true
>>> bytes.contains_any(byte_slice("Hello"), "abc")
falsecontains_rune
contains_rune(b byte_slice, r rune) boolReports whether the rune is contained in the UTF-8-encoded byte slice.
>>> bytes.contains_rune(byte_slice("Hello"), "H")
true
>>> bytes.contains_rune(byte_slice("Hello"), "h")
falsecontains
contains(b, subslice byte_slice) boolContains reports whether subslice is within b.
>>> bytes.contains(byte_slice("seafood"), byte_slice("foo"))
true
>>> bytes.contains(byte_slice("seafood"), byte_slice("bar"))
falsecount
count(s, sep byte_slice) intCounts the number of non-overlapping instances of sep in s. If sep is an empty slice, Count returns 1 + the number of UTF-8-encoded code points in s.
>>> bytes.count(byte_slice("cheese"), byte_slice("e"))
3equals
equals(a, b byte_slice) boolReports whether a and b are the same length and contain the same bytes.
>>> bytes.equals(byte_slice("Hello"), byte_slice("Hello"))
true
>>> bytes.equals(byte_slice("Hello"), byte_slice("hello"))
falsehas_prefix
has_prefix(s byte_slice, prefix byte_slice) boolTests whether the byte slice s begins with prefix.
>>> bytes.has_prefix(byte_slice("Gopher"), byte_slice("Go"))
true
>>> bytes.has_prefix(byte_slice("Gopher"), byte_slice("C"))
falsehas_suffix
has_suffix(s byte_slice, suffix byte_slice) boolTests whether the byte slice s ends with suffix.
>>> bytes.has_suffix(byte_slice("Amigo"), byte_slice("go"))
true
>>> bytes.has_suffix(byte_slice("Amigo"), byte_slice("O"))
falseindex_any
index_any(s byte_slice, chars string) intInterprets s as a sequence of UTF-8-encoded code points. Returns the byte index of the first occurrence in s of any of the code points in chars. Returns -1 if chars is empty or if there are no code point in common.
>>> bytes.index_any(byte_slice("chicken"), "aeiou")
2
>>> bytes.index_any(byte_slice("bcd"), "aeiou")
-1index_byte
index_byte(b byte_slice, c byte) intReturns the index of the first occurrence of c in b, or -1 if c is not present.
>>> bytes.index_byte(byte_slice("golang"), "g")
0
>>> bytes.index_byte(byte_slice("golang"), "x")
-1index_rune
index_rune(s byte_slice, r rune) intInterprets s as a sequence of UTF-8-encoded code points. Returns the byte index of the first occurrence in s of the given rune. Returns -1 if rune is not present.
>>> bytes.index_rune(byte_slice("chicken"), "k")
4
>>> bytes.index_rune(byte_slice("chicken"), "d")
-1index
index(s, sep byte_slice) intReturns the index of the first occurrence of sep in s, or -1 if sep is not present.
>>> bytes.index(byte_slice("chicken"), byte_slice("ken"))
4
>>> bytes.index(byte_slice("chicken"), byte_slice("kex"))
-1repeat
repeat(b byte_slice, count int) byte_sliceReturns a new byte slice consisting of count copies of b.
>>> bytes.repeat(byte_slice("a"), 3)
byte_slice("aaa")replace_all
replace_all(s, old, new byte_slice) byte_sliceReturns a copy of the slice s with all non-overlapping instances of old replaced by new.
>>> bytes.replace_all(byte_slice("aaa"), byte_slice("a"), byte_slice("b"))
byte_slice("bbb")replace
replace(s, old, new byte_slice, n int) byte_sliceReturns a copy of the slice s with the first n non-overlapping instances of old replaced by new.
>>> bytes.replace(byte_slice("aaa"), byte_slice("a"), byte_slice("b"), 2)
byte_slice("bba")