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
+16.3k Golang : How to extract links from web page ?
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+8.6k Golang : Progress bar with ∎ character
+12k Golang : Clean formatting/indenting or pretty print JSON result
+14.7k Golang : Reset buffer example
+7.9k Golang Hello World Example
+9.6k Golang : Read file with ioutil
+11.2k CodeIgniter : How to check if a session exist in PHP?
+37.5k Golang : Converting a negative number to positive number
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account