I have two global Strings, each one represents a URL that at certain times assume equal values, that is, the same URL for both Strings. I want to create an when they are different. When they are equal nothing should happen.
I tried the three methods below, none of them worked.
Does anyone know how this piece of code has to look to work ?
Thanks
url = https://agamenon.com/s/vfaqly96fqss7y9/test.txt
urlsave = https://agamenon.com/s/eh6sotgjn8q5drz/test.txt
if(url.equals(urlsalva) != 0) {
Serial.println("THE URL'S ARE DIFFERENT");
} else {
Serial.println("THE URL'S ARE THE SAME");
}
if(url.compareTo(urlsalva) != 0) {
Serial.println("THE URL'S ARE DIFFERENT");
} else {
Serial.println("THE URL'S ARE THE SAME");
}
if(url != urlsalva) {
Serial.println("THE URL'S ARE DIFFERENT");
} else {
Serial.println("THE URL'S ARE THE SAME");
}
Decided to measure the length of the two Strings I needed to compare. The one coming from a GET request was 64 characters long and the one I read from the SD card was 66. Oops, but both look the same on the serial monitor.
That's when I noticed that to write the URL to the SD card I was using the function;
myFile.println(url);
This ln was creating an extra line. It could only have been that because I eliminated the ln and now the comparison using the common operator == works. The comparison in the ten consecutive tests I did works both to confirm and to say when they are different.
A detail that made me spend hours and hours researching.