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 :

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

Advertisement