Fields

Fields 通过一个或多个空格分割字符串,如果s只包含空格,则返回s的子字符串片或空片。

Fields

函数定义

func Fields(s string) []string

代码示例

package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Printf("Fields are: %q\n", strings.Fields("  foo bar  baz   "))
    fmt.Printf("Fields are: %q\n", strings.Fields("   "))
    fmt.Printf("Fields are: %q\n", strings.Fields(""))
}

// Output:
// Fields are: ["foo" "bar" "baz"]
// Fields are: []
// Fields are: []