Golang bytes.TrimRight() function example

package bytes

TrimRight returns a subslice of the input sice by slicing off all trailing UTF-8-encoded Unicode code points that are contained in cutset (2nd parameter).

Golang bytes.TrimRight() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 str := []byte("abcdefg")
 trimmed := bytes.TrimRight(str, "dfg")
 fmt.Println(string(trimmed))


 testtrim := bytes.TrimRight(str, "ab")
 fmt.Println(string(testtrim)) // will not work
 }

Output :

abcde

abcdefg

Reference :

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

Advertisement