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 :
Advertisement
Something interesting
Tutorials
+9.9k Golang : Translate language with language package example
+10.1k Golang : Edge detection with Sobel method
+28.5k Golang : Change a file last modified date and time
+7.3k Golang : How to iterate a slice without using for loop?
+7.1k Restart Apache or Nginx web server without password prompt
+26.6k Golang : Encrypt and decrypt data with AES crypto
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+5.4k Golang : Reclaim memory occupied by make() example
+19.1k Mac OSX : Homebrew and Golang
+9.7k Golang : Eroding and dilating image with OpenCV example
+17.6k Convert JSON to CSV in Golang