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
+11.3k Golang : Intercept and process UNIX signals example
+51.4k Golang : Check if item is in slice/array
+5.8k Golang : Launching your executable inside a console under Linux
+10.3k Golang : Convert file content to Hex
+12.6k Golang : Exit, terminating or aborting a program
+6k Golang : How to verify input is rune?
+9.4k Golang : Apply Histogram Equalization to color images
+21.4k Curl usage examples with Golang
+19.2k Golang : Populate dropdown with html/template example
+13.5k Golang : Read XML elements data with xml.CharData example
+16.1k Golang : How to check if input from os.Args is integer?
+10k Golang : Read file and convert content to string