Hello everyone \o/,
I'm trying to compare the UID of a RFID device and run some action if the UID match the registered UID.
Even if my two strings look alike, the comparison return nothing.
- I have tried the trim() function => Does nothing to my string (visually, at least)
- I have tried the remove to remove what looks like a "\n" at the beginning and/or tried to add it in the string to compare.
- I have tried the strncmp() function, but I cannot make it work as it's expecting a const char*.
Is there a simple way to compare string without caring all the strange possible space character or \n ?
Or may be my issue is somewhere else....
This is the last state of the code :
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
//Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
//Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
content.toUpperCase();
content.remove(0,1);
Serial.println(content);
Serial.print("supposed to compare :");
Serial.print("\n04 36 70 D2 13 12 90");
if (content=="\n04 36 70 D2 13 12 90" && content=="\n04 6B 1F 02 CD 12 90"){
Serial.print("Hello world");
delay(3000);
}
Picture in the serial monitor :
