Golang bufio.ScanLines() function example
package bufio
ScanLines is a split function for a Scanner that returns each line of text, stripped of any trailing end-of-line marker. The returned line may be empty. The end-of-line marker is one optional carriage return followed by one mandatory newline. In regular expression notation, it is
\r?\n
. The last non-empty line of input will be returned even if it has no newline.
Golang bufio.ScanLines() function usage example
file, err := os.Open("dummy.txt")
if err != nil {
panic(err.Error())
}
defer file.Close()
reader := bufio.NewReader(file)
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
Advertisement
Something interesting
Tutorials
+28.6k Golang : Save map/struct to JSON or XML file
+28.7k Golang : JQuery AJAX post data to server and send data back to client example
+18k Golang : Implement getters and setters
+19.1k Golang : Archive directory with tar and gzip
+7k Golang : Convert source code to assembly language
+31.6k Golang : Copy directory - including sub-directories and files
+20.1k Golang : Convert date string to variants of time.Time type examples
+42k Golang : Convert []byte to image
+6.8k Golang : Not able to grep log.Println() output
+11.7k Golang : Print UTF-8 fonts on image example
+31.4k Golang : Math pow(the power of x^y) example