August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, you will learn how to read a text file character by character, which is a pretty rare requirement unless you want to develop a text editor. The relevant Go code will be saved as byCharacter.go, which will be presented in four parts.
The first part of byCharacter.go is shown in the following Go code:
package main
import (
"bufio"
"flag"
"fmt"
"io"
"os"
)
As you can see, you will not need to use regular expressions for this task.
The second code segment from byCharacter.go is as follows:
func charByChar(file string) error { var err error f, err := os.Open(file) if err != nil { return err } defer f.Close() r := bufio.NewReader(f) for { line, err := r.ReadString('\n') if err == io.EOF ...Read now
Unlock full access