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
+9.9k Golang : Translate language with language package example
+6.6k Golang : Embedded or data bundling example
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+8.4k Your page has meta tags in the body instead of the head
+7.1k Golang : A simple forex opportunities scanner
+9.4k Facebook : Getting the friends list with PHP return JSON format
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+25.4k Golang : Generate MD5 checksum of a file
+18k Golang : Get all upper case or lower case characters from string example
+16.5k Golang : Get IP addresses of a domain name
+23.5k Golang : Read a file into an array or slice example
+23.7k Find and replace a character in a string in Go