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
+14k Golang : Compress and decompress file with compress/flate example
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+7.9k Golang : Get today's weekday name and calculate target day distance example
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+17.9k Golang : How to make a file read only and set it to writable again?
+13k Swift : Convert (cast) Int to String ?
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+20.8k Golang : Convert date string to variants of time.Time type examples
+5.6k Golang : Detect words using using consecutive letters in a given string