Standard library / bytes

bytes.TrimSpace()

Removes leading and trailing Unicode whitespace, not internal whitespace. The returned slice may alias the input. Expected stdout: 'سلام\n'.

Formal Syntax & Structure

go syntaxgo
func TrimSpace(s []byte) []byte

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.

Return Value

[]byte

Removes leading and trailing Unicode whitespace, not internal whitespace. The returned slice may alias the input.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  fmt.Println(string(bytes.TrimSpace([]byte("  سلام  "))))}
Go Reference