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
Convert specific UTC date time to PST, HST, MST and SGT
Example: How to use ReadFull from IO Package in Golang?
How To Make an HTTP Server in Golang?
Golang Functions Returning Multiple Values
How to check if a string contains only letters in Golang?
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time
Get Year, Month, Day, Hour, Min and Second from a specified date
How to handle HTTP Get response?
How to find out element position in slice?
How to create Empty and Nil Slice?