Standard library / bytes

bytes.Cut()

Splits at the first separator, returning before, after and found. If absent, before is the original input and after is empty. Returned slices can share the original backing array. Expected stdout: 'id 7 true\n'.

Formal Syntax & Structure

go syntaxgo
func Cut(s, sep []byte) (before, after []byte, found bool)

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
sep[]byteSeparator or search sequence.

Return Value

(before, after []byte, found bool)

Splits at the first separator, returning before, after and found. If absent, before is the original input and after is empty. Returned slices can share the original backing array.

Working Example

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