Golang bufio.ScanWords() function example
package bufio
ScanWords is a split function for a Scanner that returns each space-separated word of text, with surrounding spaces deleted. It will never return an empty string. The definition of space is set by unicode.IsSpace.
Golang bufio.ScanWords() function usage example
file, err := os.Open("words.txt")
if err != nil {
panic(err.Error())
}
defer file.Close()
reader := bufio.NewReader(file)
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
fmt.Printf("%s ", scanner.Text())
}
Reference :
Advertisement
Something interesting
Tutorials
+5.2k PHP : See installed compiled-in-modules
+11.1k Golang : Simple image viewer with Go-GTK
+22.8k Golang : untar or extract tar ball archive example
+17.4k Golang : Get future or past hours, minutes or seconds
+10.6k Android Studio : Simple input textbox and intercept key example
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+12.5k Golang : "https://" not allowed in import path
+8k Golang : Get all countries phone codes
+9.2k Golang : Create and shuffle deck of cards example
+8.9k Golang : Gaussian blur on image and camera video feed examples
+12.6k Golang : flag provided but not defined error
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents