Reading with a scanner
Scanner is part of the bufio package. It is useful for stepping through files at specific delimiters. Commonly, the newline character is used as the delimiter to break up a file by lines. In a CSV file, commas would be the delimiter. The os.File object can be wrapped in a bufio.Scanner object just like a buffered reader. We will call Scan() to read up to the next delimiter, and then, use Text() or Bytes() to get the data that was read.
The delimiter is not just a simple byte or character. There is actually a special function, which you have to implement, that will determine where the next delimiter is, how far forward to advance the pointer, and what data to return. If no custom SplitFunc type is provided, it defaults ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access