1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package main
import ( "fmt" "strings" )
func main() { fmt.Printf("%q\n", strings.Fields("How old \t are you"))
fmt.Printf("%q\n", strings.FieldsFunc("How old \t are you", func(r rune) bool { return '\t' == r }))
fmt.Printf("%q\n", strings.Split("How,old,are,you", "w,"))
fmt.Printf("-1 %q\n", strings.SplitN("How,old,are,you", ",", -1)) fmt.Printf("0 %q\n", strings.SplitN("How,old,are,you", ",", 0)) fmt.Printf("1 %q\n", strings.SplitN("How,old,are,you", ",", 1)) fmt.Printf("2 %q\n", strings.SplitN("How,old,are,you", ",", 2)) }
|