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
+8.9k Golang : Find network service name from given port and protocol
+9.7k Golang : Eroding and dilating image with OpenCV example
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+6.8k Golang : Calculate pivot points for a cross
+11.9k Golang : Determine if time variables have same calendar day
+10.5k Swift : Convert (cast) String to Integer
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+25.7k Golang : missing Mercurial command
+36.5k Golang : Save image to PNG, JPEG or GIF format.
+36.3k Golang : How to split or chunking a file to smaller pieces?
+16.1k Golang : How to check if input from os.Args is integer?
+12.6k Golang : Get absolute path to binary for os.Exec function with exec.LookPath