Standard library / bytes

bytes.CutPrefix()

Removes the exact prefix if present and reports success; otherwise returns the input unchanged. Returned slices can share the original backing array. Expected stdout: '7 true\n'.

Formal Syntax & Structure

go syntaxgo
func CutPrefix(s, prefix []byte) (after []byte, found bool)

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
prefix[]byteLeading sequence to match.

Return Value

(after []byte, found bool)

Removes the exact prefix if present and reports success; otherwise returns the input unchanged. Returned slices can share the original backing array.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  a, ok := bytes.CutPrefix([]byte("id:7"), []byte("id:"))  fmt.Println(string(a), ok)}
Go Reference