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
+9k Golang : Build and compile multiple source files
+10.9k Golang : Get UDP client IP address and differentiate clients by port number
+5.6k Fix fatal error: evacuation not done in time problem
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+32.7k Golang : Regular Expression for alphanumeric and underscore
+7.8k Golang : Load DSA public key from file example
+20.2k Golang : Compare floating-point numbers
+6.4k Golang : Break string into a slice of characters example
+20.2k Golang : How to get struct tag and use field name to retrieve data?
+43.3k Golang : Convert []byte to image
+10k Golang : Convert octal value to string to deal with leading zero problem