Golang bytes.TrimSpace() function example
package bytes
TrimSpace returns a subslice of the input slice by slicing off all leading and trailing white space, as defined by Unicode.
Golang bytes.TrimSpace() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
str := []byte(" \t\r\n Hello, World!\r\n ")
trimmed := bytes.TrimSpace(str)
fmt.Println(string(trimmed))
}
Output :
Hello, World!
Reference :
Advertisement
Something interesting
Tutorials
+12.2k Golang : calculate elapsed run time
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+26.8k Golang : Convert file content into array of bytes
+5.9k Golang : Shuffle array of list
+11.5k CodeIgniter : Import Linkedin data
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+5.3k Golang : How to deal with configuration data?
+7.9k Swift : Convert (cast) String to Float
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+10.6k Golang : Flip coin example
+35.9k Golang : Integer is between a range
+7.5k Golang : Gorrila set route name and get the current route name