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
Different ways to convert Byte Array into String
Regular expression for matching HH:MM time format in Golang
Replace first occurrence of string using Regexp
Regular expression to extract filename from given path in Golang
How to count number of repeating words in a given String?
How to print string with double quote in Go?