Golang bytes.TrimFunc() function example

package bytes

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

Golang bytes.TrimFunc() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 str := []byte("abcdefghijk")

 inner_func := func(r rune) bool {
 return r <= 'c' || r >= 'i'
 }

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

 }

Output :

defgh

Reference :

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

Advertisement