Parsing through String to compare or find # of duplicates

Hi there, so I have a string I made:

"<0013A20040F7442C,100.134,0.254,0.0,0.0,99.1><0013A20040F7442C,100.134,0.254,0.0,0.0,99.1>
"

Basically I want to know how many “.” are in the String or look for how many times I have this “013A200” in the String array.

Thanks!

If you insist on pissing away resources on the String class, the indexOf() method takes an optional second argument that says where to begin scanning. If you begin scanning one place after the last dot found, and increment a counter while the indexOf() value is positive, you can count the dots.

I am using a Teensy 3.2 which has a lot of resources to play with :)

brolly759:
I am using a Teensy 3.2 which has a lot of resources to play with :slight_smile:

start away from String class, not because you have resources, but because you don’t want problems later on.

try using strchr() like this:

char myData[] = "<0013A20040F7442C,100.134,0.254,0.0,0.0,99.1><0013A20040F7442C,100.134,0.254,0.0,0.0,99.1>";

void setup() 
{
  Serial.begin(9600);
  int charCount = 0;
  char* ptr;
  ptr = strchr(myData, '.');
  while(ptr != NULL)
  {
    charCount++;
    ptr = strchr(ptr + 1, '.');
  }
  Serial.println(charCount);
  Serial.println("Done");
}

void loop() 
{
}

I append to the string and add more data to the end of it, I search, delete, and replace old data and replace the small piece of data that is associated with that MAC. I can do all of that if I use an Array?

brolly759: I append to the string and add more data to the end of it, I search, delete, and replace old data and replace the small piece of data that is associated with that MAC. I can do all of that if I use an Array?

how else would you do it?

I can do all of that if I use an Array?

yEs.