Hi there, I have a CSV file I’m reading and the result i’m getting for the first record I’m reading has a space at the start of it (or maybe it’s not a space but that’s how it shows up in the console). I can’t see any reason for this or any documentation mentioning it.
Can anyone point me in the right direction? Thanks.
package main
import (
"encoding/csv"
"fmt"
"os"
)
func main() {
// Struct to hold schedule.csv
type Sched struct {
schDate string
schShift string
}
// hardcodings
filename := "schedule.csv"
// Open CSV file
f, err := os.Open(filename)
if err != nil {
panic(err)
}
defer f.Close()
// Read File into a Variable
lines, err := csv.NewReader(f).ReadAll()
if err != nil {
panic(err)
}
// Loop through lines & turn into object
for _, line := range lines {
data := Sched{
schDate: line[0],
schShift: line[1],
}
if data.schShift == "" {
break
}
fmt.Printf("START:%s\n", data.schDate)
}
}