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 get current IP form ipify.org ?
Golang import package inside package
How to find out element position in slice?
Example: ReadAll, ReadDir, and ReadFile from IO Package
How to wait for Goroutines to Finish Execution?
How to fix race condition using Atomic Functions in Golang?
Regular expression to extract domain from URL
Creating a Function in Golang
Different ways for Integer to String Conversions
How to read names of all files and folders in current directory?