Reading 35 ascii characters from card reader track

Hello there. What could be the best approach to read large amount of ASCII data from a track in a card?.
I have a serial card reader (ID Tech IDMB) and data contained in the three tracks of a card in the standard format: %ABCD.........? and ;ABCD............?. My initial interest is to know the best approach to read a maximum of 35 ASCII characters from one track using my Arduino uno. For example:
%FIELD1 FIELD2 FIELD3 FIELD4 FIELD5?. I did this in the past but reading a maximum of 3 and 4 ascii characters and saving them in one variable. What I need to do now is to read a maximum of 35 ASCII character from one track. Should I create an ascii table? How to save them? I will appreciate any help. Thank you.

A char array is the most obvious way to store them. I suggest you keep the array null-terminated, so remember to size the array to include the final terminating char.

Just posted this in another thread:

Arrch:
What you need is an array of chars:

const int maxLength = 50;

char readString[maxLength];




You also need an index variable (either global or static) that will keep track of where in the array you are.



int strIndex = 0;




And lastly, you need a character that will signal that you are done transmitting your string. This will depend on what program is sending you the string. The Arduino's Serial Monitor, for example can append '\r' and/or '\n' to the end of each transmission.



#define END_OF_STRING '\n'




From there you just need to read a character as you receive it and decide whether to parse the data and reset the array (if it's the END_OF_STRING marker):



// Do Something with the string
readString[0] = '\0'; // clear the array
strIndex = 0; // reset the index to 0




or add it to the array:



readString[strIndex] = inChar; // put the new char in the array
strIndex++; // increment our index for the next char
readString[strIndex] = '\0'; // null terminate our array to make it a proper string

Thank you PeterH and Arrch.
Arrch, I will check your post and start to build the code and post here if I run into issues.

Do the strings sent start with either a "%" or ";" and always end with a "?" ?

It's a standard format B called sentinel.
For track 1: Start sentinel = %
End sentinel = ?

For track 2: Start sentinel = ;
End sentinel = ?

Track 3 is virtually unused by the major worldwide networks.

For a better understanding read Digital card - Wikipedia or google magnetic stripe card sources.

Code posted by others that captures the string between < and >. You could change that to % and ?.

String cmd;
String fullCmd;
boolean cmdComplete=false;

void setup () {
  Serial.begin(9600);
 cmd="";
 Serial.println("start duel delimit");
 }

void loop() {
  char c;
  while(Serial.available()) {
    c=Serial.read();
    if (c=='<') {
      cmd="";
    } else if (c=='>') {
      fullCmd=cmd;
      cmd="";
      cmdComplete=true;
      break;
    } else {
       cmd+=c;
    }
  }
  if (cmdComplete==true) {
    Serial.println('<' + fullCmd + "_OK>");
    cmdComplete=false;
  }
}

Thanks zoomkat for the code. I really didn't have issues to capture few characters. My challenge is to capture/save and use them for validation purposes. Initially I thought to use a bar code reader sample but the one provided by Arrch looks like a good approach.

lots of ways to parse captured strings to extract the desired data