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
+4.4k Golang : Valued expressions and functions example
+16.9k Golang : Set up source IP address before making HTTP request
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+9.1k Golang : Intercept and compare HTTP response code example
+12.1k Golang : convert(cast) string to integer value
+7.7k Golang : How to execute code at certain day, hour and minute?
+9.8k Golang : Qt get screen resolution and display on center example
+6.5k Grep : How to grep for strings inside binary data
+4.6k Mac OSX : Get disk partitions' size, type and name
+12.2k Golang : Get remaining text such as id or filename after last segment in URL path
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format