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
+35.9k Golang : Integer is between a range
+9.4k Facebook : Getting the friends list with PHP return JSON format
+19.4k Golang : Fix cannot download, $GOPATH not set error
+22.1k Golang : Repeat a character by multiple of x factor
+5.3k Swift : Convert string array to array example
+11.2k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+12.2k Golang : Get remaining text such as id or filename after last segment in URL path
+9.4k Golang : Create unique title slugs example
+7.4k Golang : How to detect if a sentence ends with a punctuation?
+24k Golang : Call function from another package
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function