September 2017
Intermediate to advanced
466 pages
9h 33m
English
This is a very common scenario, as you often will need to get all the data from a given column of a structured text file in order to analyze it afterward. The code of readColumn.go, which prints values in the third column, will be presented in two parts.
The first part is as follows:
package main
import (
"fmt"
"strings"
)
func main() {
var s [3]string
s[0] = "1 2 3"
s[1] = "11 12 13 14 15 16"
s[2] = "-1 2 -3 -4 -5 6"
Here, you import the required Go packages and define a string with three lines using an array with three elements.
The second part contains the following Go code:
column := 2 for i := 0; i < len(s); i++ { data := strings.Fields(s[i]) if len(data) >= column { fmt.Println((data[column-1])) ...Read now
Unlock full access