Table of Contents
- Arduino String.equalsIgnoreCase() Function
- Syntax
- Parameters
- Return
- How to Use String.equalsIgnoreCase() Function in Arduino
- Conclusion
Arduino String.equalsIgnoreCase() Function
The String.equalsIgnoreCase() function is used to compare two strings for equality while ignoring their case sensitivity.
This function returns true if the two strings have the same characters in the same sequence, regardless of the case of the letters.
For example, “LINUX” and “linux” would be considered equal when compared with this function.
Syntax
The syntax of the String.equalsIgnoreCase() function is as follows:
Here, string1 and string2 are the two strings to be compared.
Parameters
The String.equalsIgnoreCase() function takes only one parameter, which is the string to be compared with the original string.
Return
This function returns either true or false.
True: If string1 matches with string2 (ignoring cases).
False: If string1 doesn’t match with string2.
How to Use String.equalsIgnoreCase() Function in Arduino
Now we will discuss an Arduino code that uses this function and compare two strings with different cases.
Serial.begin(9600);
String firstString = "linuxhint";
String secondString = "LINUXHINT";
if (firstString.equalsIgnoreCase(secondString))
Serial.println("The two strings are equal.");
else
Serial.println("The two strings are not equal.");
}
void loop() {
}
Here we have two string variables, firstString and, secondString, that contain the same characters but with different cases. We use the equalsIgnoreCase() function to compare them for equality, regardless of case sensitivity.
The program will output “The two strings are equal.” to the serial monitor because both strings are equal, only their case is different.
Conclusion
The String.equalsIgnoreCase() function can compare two different strings by ignoring the case sensitivity. This article covers the syntax, parameter, and return value of this function. For details on String.equalsIgnoreCase() function, read the article.