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
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+6.9k Mac/Linux/Windows : Get CPU information from command line
+12.6k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+10.4k Golang : cannot assign type int to value (type uint8) in range error
+6.8k Golang : Find the longest line of text example
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+33.8k Golang : convert(cast) bytes to string
+15.3k Golang : Get all local users and print out their home directory, description and group id
+9k Golang : How to use Gorilla webtoolkit context package properly
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+5.8k Golang : Launching your executable inside a console under Linux