Skip to content

Reading From CSV files into quote object causes error #12

@FarhanSajid1

Description

@FarhanSajid1

When reading a csv file into a quote object there is a slight error which needs to be checked before reading the file.

NewQuoteFromCSV(symbol, csv string) (Quote, error) {

	tmp := strings.Split(csv, "\n")
	numrows := len(tmp)
	q := NewQuote(symbol, numrows-1)

	for row, bar := 1, 0; row < numrows; row, bar = row+1, bar+1 {
		line := strings.Split(tmp[row], ",") # we need to add in a conditional check as such
                if len(line) != 6 {
			break
		}

The reason being is that the way that the "records" are being written a "\n" is automatically appended at the end, this simple check worked and helped me avoid the annoying out of bounds error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions