Arduino

How to Convert String to Lower and Upper Case in Arduino

Arduino programming is very versatile when it comes to modifying data. We can change output into different forms using Arduino functions. Arduino has two main functions using which we can easily convert any string alphabet into lower- or upper-case letters. Using the user’s string as input, we will convert it into a new string having all letters lower or upper case.

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

String.toLowerCase()

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

String Test_String;
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

String.toUpperCase()

Parameter Values
A variable of type String.

Return Values
No value return, it just modified the string characters to upper case letters.

Example Code

String Test_String;
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.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.