How to Convert String to Lower Case in Arduino
Using Arduino IDE functions, we can modify strings and convert them into lower case letters. String.toLowerCase() function can give us a lower-case version of any string. This function does not return any value, it just modifies the defined string to lower case letters.
Syntax
Parameter Values
A variable of type String.
Return Values
There is no return value, it just modified the string characters to lowercase letters.
Example Code
void setup() {
Serial.begin(9600); /*Serial communication begin*/
Test_String = "LINUXHINT.COM";
Serial.print("String Before Conversion: ");
Serial.println(Test_String); // string before conversion to lowercase
Test_String.toLowerCase();
Serial.print("String After Conversion: ");
Serial.println(Test_String); // string after conversion to lowercase
}
void loop() {
}
In above code we initialized a Test_String and in setup part of code first serial communication is established by defining baud rate. Next our new string is defined. To print on the serial monitor we used the Serial.println() function.
After that using the .toLowerCase() function all alphabets of Test_String are converted to lowercase letters. Next, we printed the lower-case string using Serial.println() on the serial monitor.
Using Test_String.toLowerCase() function any string alphabets can be converted into lower case.
Output
Output can be seen using a serial monitor. Before and after conversion to lower case letter can be seen. All capital letters of Test_String are converted to lowercase letters.
How to Convert String to Upper Case in Arduino
Using Arduino IDE functions, we can modify strings and convert them into upper case letters. String.toUpperCase() function can give us an upper-case version of any string. This function does not return any value, it just modifies the defined string to upper case letters.
Syntax
Parameter Values
A variable of type String.
Return Values
No value return, it just modified the string characters to upper case letters.
Example Code
void setup() {
Serial.begin(9600);
Test_String = "linuxhint.com";
Serial.print("String Before Conversion: ");
Serial.println(Test_String); // string before conversion to uppercase
Test_String.toUpperCase();
Serial.print("String After Conversion: ");
Serial.println(Test_String); // string after conversion to uppercase
}
void loop() {
}
In above code a test string is defined as Test_String after that the setup function of code serial communication begins using baud rate. Later we declared our test string as “linuxhint.com” then printed it on the serial monitor using the Serial.print command.
Test_String.toUpperCase() function will do the work here, it will convert all small case letters inside our test string to uppercase. Next Test_String with all upper-case letters is printed over the serial monitor.
Output
Serial monitor displays the output. Before and after conversion to upper case letter can be seen. All small letters of Test_String are converted to Upper case letters.
Conclusion
Arduino programming has two functions String.toLowerCase() and String.toUpperCase() using which we can convert string data into lower case and upper-case letters. To illustrate the use of both functions we have taken a string and transformed its entities to lower and upper case in their respective codes.