Golang bytes.Trim() function example
package bytes
Trim returns a subslice of the input slice by slicing off all leading and trailing UTF-8-encoded Unicode code points contained in cut set (2nd parameter).
Golang bytes.Trim() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
str := []byte("Hi! How are you ? no")
trimmed := bytes.Trim(str, "Hi!no") // leading and trailing
fmt.Println(string(trimmed))
num := []byte("123456789")
trimmed2 := bytes.Trim(num, "1789") // leading and trailing
fmt.Println(string(trimmed2))
}
Output :
How are you ?
23456
Advertisement
Something interesting
Tutorials
+40.1k Golang : UDP client server read write example
+20.6k Golang : Secure(TLS) connection between server and client
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+15.3k Golang : How to get Unix file descriptor for console and file
+9.7k Golang : Populate slice with sequential integers example
+8.2k How to show different content from website server when AdBlock is detected?
+9.4k Golang : Qt Yes No and Quit message box example
+12.1k Golang : Split strings into command line arguments
+33.6k Golang : How to check if slice or array is empty?
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+5.2k Python : Create Whois client or function example