csv.NewReader adds space to front of first record

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)
	}
}

I opened it in notepad and saved again with no odd characters shown. Thought that might have cleared those so I was focused on the code. I’ll start my CSV from scratch and see what I get

And maybe thats all it was :slight_smile: sometimes it’s not my coding
Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.