Standard library / bytes

bytes.TrimSuffix()

Removes one exact suffix if present, otherwise returns input unchanged. The returned slice may alias the input. Expected stdout: 'Go.txt\n'.

Formal Syntax & Structure

go syntaxgo
func TrimSuffix(s, suffix []byte) []byte

Parameters & Attributes

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

Return Value

[]byte

Removes one exact suffix if present, otherwise returns input unchanged. The returned slice may alias the input.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  fmt.Println(string(bytes.TrimSuffix([]byte("Go.txt.txt"), []byte(".txt"))))}
Go Reference