Golang bytes.TrimSuffix() function example

package bytes

TrimPrefix returns the input slice without the provided trailing suffix string(2nd parameter). If the given input slice doesn't start with suffix, the original input slice is returned unchanged.

Golang bytes.TrimSuffix() function usage example

 package main

 import (
 "fmt"
 "bytes"
 )

 func main() {
 str := []byte("Bye Bye!")

 trimmed := bytes.TrimSuffix(str,[]byte("Bye!"))

 fmt.Println(string(trimmed))

 fmt.Println(string(trimmed) + "Dear!")
 }

Output :

Bye

Bye Dear!

Reference :

http://golang.org/pkg/bytes/#TrimSuffix

Advertisement