Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
lowercase
character
communitycreator

How to convert a character to lowercase in Rust

okwudili onyejiaku

Overview

We can covert a character to lowercase in Rust by passing the character to to_lowercase() method.

Syntax

character.to_lowercase()
Syntax for converting a character to lowercase in Rust

Parameters

character: This is the character that we want to convert to lowercase.

Return value

The value returned is an lowercase equivalent of the character character.

Example

fn main(){
  // create some characters
  let char1 = 'o';
  let char2 = 'T';
  let char3 = 'A';
  let char4 = 'Z';
  let char5 = 'x';

  // Convert to lowercase
  println!("{}", char1.to_lowercase());  
  println!("{}", char2.to_lowercase());  
  println!("{}", char3.to_lowercase()); 
  println!("{}", char4.to_lowercase());
  println!("{}", char5.to_lowercase());
}
Convert characters to Lowercase in Rust

Explanation

  • Lines 3–7: We create some characters.
  • Lines 10–14: We convert the characters to lowercase using the to_lowercase() method and print the values to the console.

RELATED TAGS

rust
lowercase
character
communitycreator
RELATED COURSES

View all Courses

Keep Exploring