Standard library / strings

strings.Fields()

Splits on runs of Unicode whitespace, discarding empty fields. Expected stdout: '[a|b]\n'.

Formal Syntax & Structure

go syntaxgo
func Fields(s string) []string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.

Return Value

[]string

Splits on runs of Unicode whitespace, discarding empty fields.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  v := strings.Fields(" a\t b ")  fmt.Print("[")  for i, x := range v {    if i > 0 {      fmt.Print("|")    }    fmt.Print(string(x))  }  fmt.Println("]")}
Go Reference