Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
lowercase
character
communitycreator

How to check if a character is in lowercase in Rust

okwudili onyejiaku

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());
}
Check if a character is lowercase in Rust

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.

RELATED TAGS

rust
lowercase
character
communitycreator
RELATED COURSES

View all Courses

Keep Exploring