Go Package bufio: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://pkg.go.dev/bufio =Internal= * Standard Library =Overview= =Reading a Text File Line by Line=")
 
Line 5: Line 5:
=Overview=
=Overview=
=Reading a Text File Line by Line=
=Reading a Text File Line by Line=
<syntaxhighlight lang='go'>
import (
"bufio"
"os"
)
f, err := os.Open("/Users/ovidiu/tmp/adc.txt")
if err != nil {
  ...
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
  line := scanner.Text()
  ...
}
</syntaxhighlight>

Revision as of 23:25, 10 January 2024

External

Internal

Overview

Reading a Text File Line by Line

import (
	"bufio"
	"os"
)

f, err := os.Open("/Users/ovidiu/tmp/adc.txt")
if err != nil {
  ...
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
  line := scanner.Text()
  ...
}