Code Logo

Check Letter with is_alphabetic()

Published at25 Jul 2026
Rust String Handling Easy 0 views
Like0

Write a Rust function that takes a single character and returns true if it is an alphabetic letter using the char::is_alphabetic() method. This method checks if the character belongs to the Unicode Alphabetic category, which includes both uppercase and lowercase letters.

The char type in Rust represents a single Unicode scalar value (32-bit). Unlike C's char which is a byte, Rust's char can represent any Unicode character. The is_alphabetic() method is one of many category-checking methods on char, including is_numeric(), is_whitespace(), is_alphanumeric(), and more.

Rust's char methods are Unicode-aware by default. Unlike simple ASCII range checks (c >= 'a' && c <= 'z'), is_alphabetic() correctly handles accented characters and non-Latin alphabets. This makes Rust code more portable and correct for international applications.

Time complexity is O(1) as is_alphabetic() uses a character category lookup table. Space complexity is O(1). The method compiles to a constant-time lookup based on the character's Unicode category.

Edge cases include uppercase letters (return true), lowercase letters (return true), digits (return false), whitespace (return false), punctuation (return false), and Unicode letters from non-Latin scripts (also return true).

Example Input & Output

Example 1
Input
"a"
Output
true
Explanation

'a' is a letter

Example 2
Input
" "
Output
false
Explanation

Space is not a letter

Example 3
Input
"m"
Output
true
Explanation

'm' is a letter

Example 4
Input
"5"
Output
false
Explanation

'5' is a digit, not a letter

Example 5
Input
"Z"
Output
true
Explanation

'Z' is a letter

Algorithm Flow

Recommendation Algorithm Flow for Check Letter with is_alphabetic()
Recommendation Algorithm Flow for Check Letter with is_alphabetic()

Solution Approach

fn solution(c: char) -> bool {
    c.is_alphabetic()
}

Best Answers

rust - Approach 1
fn solution(c: char) -> bool {
    c.is_alphabetic()
}