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
+9.1k Golang : Simple histogram example
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+17.5k Golang : Linked list example
+20.6k Golang : Secure(TLS) connection between server and client
+11.2k Golang : How to pipe input data to executing child process?
+14.9k Golang : Basic authentication with .htpasswd file
+7.9k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+9.5k Golang : Get all countries currencies code in JSON format
+14.1k Javascript : Prompt confirmation before exit
+20.2k Golang : Count number of digits from given integer value
+6.5k Unix/Linux : How to get own IP address ?