Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isolate row with parsing_row_by_row_sd_card #31

Open
stef-ladefense opened this issue Aug 4, 2024 · 1 comment
Open

isolate row with parsing_row_by_row_sd_card #31

stef-ladefense opened this issue Aug 4, 2024 · 1 comment

Comments

@stef-ladefense
Copy link

hi,

i use your exemple parsing_row_by_row_sd_card.

I have the display of the lines contained in my csv and number of lines in csv.
but then how can I retrieve only the values ​​of a line #n?

not found this

thank

Stef

@michalmonday
Copy link
Owner

Hello, sadly there's no supported way to do that. It only could be done by parsing and ignoring previous lines. For example like this:

void ignore_n_lines(CSV_Parser &cp, int n) {
    for (int i = 0; i < n; i++) {
        if (!cp.parseRow()){
            Serial.println("ERROR: Failed to ignore " + String(n) + " lines. Stopped at index " + String(i));
            return;
        }
    }
}

With the setup function modified like this, in this case it ignores the first 3 lines:

// parseRow calls feedRowParser() continuously until it reads a 
  // full row or until the rowParserFinished() returns true
  int row_index = 3;

  // WARNING: String indexing can't be used here because the header was not supplied to the cp object yet.
  // int32_t *ids = (int32_t*)cp["Index"];
  // char **customer_ids = (char**)cp["Customer Id"];
  // char **emails = (char**)cp["Email"];

  int32_t *ids = (int32_t*)cp[0];
  char **customer_ids = (char**)cp[1];
  char **emails = (char**)cp[9];

  ignore_n_lines(cp, row_index);
  while (cp.parseRow()) {
    // Here we could use string indexing but it would be much slower.
    // char *email = ((char**)cp["Email"])[0];

    int32_t id = ids[0];
    char *customer_id = customer_ids[0];
    char *email = emails[0];

    Serial.print(String(row_index) + ". customer_id=" + String(customer_id));
    Serial.print(", id=");
    Serial.print(id, DEC);
    Serial.print(", email=");
    Serial.println(email);
    row_index++;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants