Golang bufio scanner example | NewScanner
In this post we will see some bufio.Scanner examples which comes built-in from go language itself.
Scanner Examples
In the code section i've share 3 example usage of bufio.Scanner
- Read word from standard input
- Read line from standard input
- Read from file
Some Quick References to understand the example code better:
NewScanner
NewScanner returns a new Scanner to read from r. The split function defaults to ScanLines.
scanner.Split()
Split sets the split function for the Scanner. The default split function is ScanLines.
scanner.Scan()
Scan advances the Scanner to the next token, which will then be available through the Bytes or Text method
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.