Arduino Chaîne Des Opérateurs De Comparaison De Code

L' String comparison operators, ==, !=,>, < ,>=, <= , and the functionsequals() et equalsIgoreCase() allow you to make alphabetic comparisons between Strings. They’re useful for sorting and alphabetizing, among other things.

Arduino String Comparison Operators

The operator == and the function equals() perform identically. It’s just a matter of which you prefer. So

if (stringOne.equals(stringTwo)) {

is identical to

if (stringOne ==stringTwo) {

The greater than and less than operators evaluate strings in alphabetical order, on the first character where the two differ. So, for example "a" < "b" et "1" < "2", but "999"> "1000" because 9 comes after 1.

Caution: String comparison operators can be confusing when you’re comparing numeric strings, because you’re used to thinking of them as numbers, not strings. If you have to compare numbers, compare them as ints, floats, or longs, and not as Strings.

Circuit

There is no circuit for this example, though your Arduino must be connected to your computer via USB.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code

/*
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.
*/

String stringOne, stringTwo;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Major Components in Project

Hardware Required

  • Arduino Board

For more detail: Arduino Chaîne Des Opérateurs De Comparaison De Code


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut