Added equals() to comparison operator example

This commit is contained in:
Tom Igoe 2010-07-27 20:09:37 +00:00
parent 8a21cd9e9e
commit 570454f178
1 changed files with 19 additions and 0 deletions

View File

@ -37,6 +37,21 @@ void loop() {
if (stringOne != stringTwo) {
Serial.println(stringOne + " =! " + stringTwo);
}
// you can also use equals() to see if two strings are the same:
if (stringOne.equals(stringTwo)) {
Serial.println(stringOne + " equals " + stringTwo);
}
else {
Serial.println(stringOne + " does not equal " + stringTwo);
}
// or perhaps you want to ignore case:
if (stringOne.equalsIgnoreCase(stringTwo)) {
Serial.println(stringOne + " equals (ignoring case) " + stringTwo);
}
else {
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
}
// a numeric string compared to the number it represents:
stringOne = "1";
@ -45,6 +60,8 @@ void loop() {
Serial.println(stringOne + " = " + numberOne);
}
// two numeric strings compared:
stringOne = "2";
stringTwo = "1";
@ -114,3 +131,5 @@ void loop() {