Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
character
uppercase
communitycreator

How to check if a character is uppercase in Rust

okwudili onyejiaku

Overview

We use the is_uppercase() method to check if a character is uppercase in Rust.

Syntax

character.is_uppercase()
Syntax for the uppercase() method

Parameters

character: This is a single character whose case we want to check.

Return value

It returns a Boolean value: true or false. If the character is uppercase indeed, it returns true. Otherwise, it returns false.

Code example

fn main(){
  // Creating some characters
  let char1 = 'E';
  let char2 = 'c';
  let char3 = 'X';
  let char4 = 'r';
  let char5 = '6';

  // Checking if the characters are uppercase
  println!("{}", char1.is_uppercase());
  println!("{}", char2.is_uppercase());
  println!("{}", char3.is_uppercase());
  println!("{}", char4.is_uppercase());
  println!("{}", char5.is_uppercase());
}
Checking if a string or character is uppercase in Rust

Code explanation

  • Line 3–7: We introduce five characters.
  • Line 10–14: We use the is_uppercase() method on each character to check whether it is uppercase.

RELATED TAGS

rust
character
uppercase
communitycreator
RELATED COURSES

View all Courses

Keep Exploring