How to split a string on white-space?
The Fields function breaks a string around each instance of one or more consecutive white space characters into an Array.
Example
package main
import (
"fmt"
"strings"
)
func main() {
testString := "Australia is a country and continent surrounded by the Indian and Pacific oceans."
testArray := strings.Fields(testString)
for _, v := range testArray {
fmt.Println(v)
}
}
Most Helpful This Week
Golang HTML parser
How to iterate over an Array using for loop?
Example: How to use ReadAtLeast from IO Package in Golang?
How to use wildcard or a variable in our URL for complex routing?
How to get struct variable information using reflect package?
How to fix race condition using Atomic Functions in Golang?