Standard library / bytes

bytes.CutSuffix()

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

Formal Syntax & Structure

go syntaxgo
func CutSuffix(s, suffix []byte) (before []byte, found bool)

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
suffix[]byteTrailing sequence to match.

Return Value

(before []byte, found bool)

Removes the exact suffix 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.CutSuffix([]byte("log.txt"), []byte(".txt"))  fmt.Println(string(a), ok)}
Go Reference