Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
lowercase
uppercase
string
communitycreator

How to convert an uppercase letter or string to lowercase in Rust

okwudili onyejiaku

Overview

In Rust, the to_lowercase() method is used to convert a character or string to lowercase. It converts any letter that is not in lowercase to lowercase.

Syntax

string.to_lowercase()
Syntax for lowercase() method in Rust

Parameters

string: This is a string or a character that we want to convert in lowercase.

Return value

It returns the object, string, in lowercase.

Example

fn main(){

    // create some strings
    let gender = "M";
    let name = "OKwuDiLi";
    let role = "DEVELOPer";

    // print string in lowercase
    println!("{} in lowercase = {}", gender, gender.to_lowercase());
    println!("{} in lowercase = {}", name, name.to_lowercase());
    println!("{} in lowercase = {}", role, role.to_lowercase());
}
Convert string or character to lowercase in Rust

Explanation

  • Lines 4–6: We create some strings and a character.
  • Lines 9–11: We print these strings and characters in lowercase using the to_lowercase() method.

RELATED TAGS

rust
lowercase
uppercase
string
communitycreator
RELATED COURSES

View all Courses

Keep Exploring