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
How to set timeout for http.Get() requests in Golang?
How to remove symbols from a string in Golang?
Regular expression to extract numbers from a string in Golang
Example: Fields and FieldsFunc from BYTES Package
How to copy a map to another map?
How to check if a string contains a white space in Golang?