mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Added equals() to comparison operator example
This commit is contained in:
parent
8a21cd9e9e
commit
570454f178
@ -37,6 +37,21 @@ void loop() {
|
|||||||
if (stringOne != stringTwo) {
|
if (stringOne != stringTwo) {
|
||||||
Serial.println(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:
|
// a numeric string compared to the number it represents:
|
||||||
stringOne = "1";
|
stringOne = "1";
|
||||||
@ -45,6 +60,8 @@ void loop() {
|
|||||||
Serial.println(stringOne + " = " + numberOne);
|
Serial.println(stringOne + " = " + numberOne);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// two numeric strings compared:
|
// two numeric strings compared:
|
||||||
stringOne = "2";
|
stringOne = "2";
|
||||||
stringTwo = "1";
|
stringTwo = "1";
|
||||||
@ -114,3 +131,5 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user