Golang bufio.ScanRunes() function example
package bufio
ScanRunes is a split function for a Scanner that returns each UTF-8-encoded rune as a token. The sequence of runes returned is equivalent to that from a range loop over the input as a string, which means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd". Because of the Scan interface, this makes it impossible for the client to distinguish correctly encoded replacement runes from encoding errors.
bufio.ScanRunes() function usage example
file, err := os.Open("utf8.txt")
if err != nil {
panic(err.Error())
}
defer file.Close()
reader := bufio.NewReader(file)
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanRunes)
for scanner.Scan() {
fmt.Printf("%s ", scanner.Text())
}
Advertisement
Something interesting
Tutorials
+8.7k Golang : How to join strings?
+5.2k Golang : Issue HTTP commands to server and port example
+5.4k Python : Delay with time.sleep() function example
+8.2k How to show different content from website server when AdBlock is detected?
+5.8k Javascript : How to replace HTML inside <div>?
+7.1k Golang : Array mapping with Interface
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+17.2k Golang : When to use init() function?
+18.5k Golang : Set, Get and List environment variables
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+3.6k Java : Get FX sentiment from website example