How to check if a character is in lowercase in Rust

Overview

We can check if a character is in lowercase in Rust by using the is_lowercase() method. This method returns a Boolean value. If the character is lowercase, then a true is returned, otherwise false.

Syntax

character.is_lowercase()
Syntax to check if a character is lowercase in Rust

Parameters

There is only one parameter:

character: This is the character we want to check if it is in lowercase.

Return value

A Boolean value true or false is returned.

Example

fn main(){
// create some characters
let char1 = 'E';
let char2 = 'c';
let char3 = 'X';
let char4 = 'r';
let char5 = '6';
// check if characters are lowercase
println!("{}", char1.is_lowercase());
println!("{}", char2.is_lowercase());
println!("{}", char3.is_lowercase());
println!("{}", char4.is_lowercase());
println!("{}", char5.is_lowercase());
}

Explanation

  • Lines 3–7: We create some characters.
  • Lines 10–14: We use the is_lowercase() method to see if some of the characters created were lowercase, then we print the results.