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 Get current Date and Time in EST, UTC and MST?
How to get the current date and time with timestamp in local and other timezones ?
Example: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of Slices
Get Hours, Days, Minutes and Seconds difference between two dates [Future and Past]
How to use Ellipsis (...) in Golang?
Golang Read Write Create and Delete text file
How to kill execution of goroutine?
How to write backslash in Golang string?
Dereferencing a pointer from another package
How to create Map using the make function in Go?