Golang bytes.TrimRightFunc() function example

package bytes

TrimRightFunc returns a subslice of the input slice by slicing off all trailing UTF-8-encoded Unicode code points that satisfy the inner filter function(2nd parameter).

Golang bytes.TrimRightFunc() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 str := []byte("abcdefghijk")

 inner_func := func(r rune) bool {
 return r >= 'f'
 }

 fmt.Println(string(bytes.TrimRightFunc(str,inner_func)))

 }

Output :

abcde

Reference :

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

  See also : Golang bytes.TrimLeftFunc() function

Advertisement