mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@ -1,14 +1,14 @@
|
||||
/*
|
||||
Comparing Strings
|
||||
|
||||
Comparing Strings
|
||||
|
||||
Examples of how to compare strings using the comparison operators
|
||||
|
||||
|
||||
created 27 July 2010
|
||||
modified 2 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
http://arduino.cc/en/Tutorial/StringComparisonOperators
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
@ -33,7 +33,7 @@ void setup() {
|
||||
void loop() {
|
||||
// two strings equal:
|
||||
if (stringOne == "this") {
|
||||
Serial.println("StringOne == \"this\"");
|
||||
Serial.println("StringOne == \"this\"");
|
||||
}
|
||||
// two strings not equal:
|
||||
if (stringOne != stringTwo) {
|
||||
@ -49,7 +49,7 @@ void loop() {
|
||||
// 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);
|
||||
}
|
||||
@ -57,7 +57,7 @@ void loop() {
|
||||
// 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);
|
||||
}
|
||||
@ -81,20 +81,20 @@ void loop() {
|
||||
// comparison operators can be used to compare strings for alphabetic sorting too:
|
||||
stringOne = String("Brown");
|
||||
if (stringOne < "Charles") {
|
||||
Serial.println(stringOne + " < Charles");
|
||||
Serial.println(stringOne + " < Charles");
|
||||
}
|
||||
|
||||
if (stringOne > "Adams") {
|
||||
Serial.println(stringOne + " > Adams");
|
||||
Serial.println(stringOne + " > Adams");
|
||||
}
|
||||
|
||||
if (stringOne <= "Browne") {
|
||||
Serial.println(stringOne + " <= Browne");
|
||||
Serial.println(stringOne + " <= Browne");
|
||||
}
|
||||
|
||||
|
||||
if (stringOne >= "Brow") {
|
||||
Serial.println(stringOne + " >= Brow");
|
||||
Serial.println(stringOne + " >= Brow");
|
||||
}
|
||||
|
||||
// the compareTo() operator also allows you to compare strings
|
||||
@ -104,10 +104,10 @@ void loop() {
|
||||
stringOne = "Cucumber";
|
||||
stringTwo = "Cucuracha";
|
||||
if (stringOne.compareTo(stringTwo) < 0 ) {
|
||||
Serial.println(stringOne + " comes before " + stringTwo);
|
||||
}
|
||||
Serial.println(stringOne + " comes before " + stringTwo);
|
||||
}
|
||||
else {
|
||||
Serial.println(stringOne + " comes after " + stringTwo);
|
||||
Serial.println(stringOne + " comes after " + stringTwo);
|
||||
}
|
||||
|
||||
delay(10000); // because the next part is a loop:
|
||||
@ -116,16 +116,16 @@ void loop() {
|
||||
|
||||
while (true) {
|
||||
stringOne = "Sensor: ";
|
||||
stringTwo= "Sensor: ";
|
||||
stringTwo = "Sensor: ";
|
||||
|
||||
stringOne += analogRead(A0);
|
||||
stringOne += analogRead(A0);
|
||||
stringTwo += analogRead(A5);
|
||||
|
||||
if (stringOne.compareTo(stringTwo) < 0 ) {
|
||||
Serial.println(stringOne + " comes before " + stringTwo);
|
||||
}
|
||||
Serial.println(stringOne + " comes before " + stringTwo);
|
||||
}
|
||||
else {
|
||||
Serial.println(stringOne + " comes after " + stringTwo);
|
||||
Serial.println(stringOne + " comes after " + stringTwo);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user