Keyboard shortcuts

Press โ† or โ†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

String is alphabetic or alphanumeric

  • is_alphabetic
  • is_alphanumeric
  • all
  • chars

The char type has methods such as is_alphabetic and is_alphanumeric and several other similar methods.

fn main() {
    let strings = vec!["text", "t xt", "t,xt", "๐Ÿ˜‡๐Ÿ˜ˆ", "ฮฉุฃใ…รฑ", "ืฉืœื•ื"];

    for text in &strings {
        println!("{}: {}", text, text.chars().all(|chr| chr.is_alphabetic()));
    }
    println!();

    for text in &strings {
        println!("{}: {}", text, text.chars().all(char::is_alphabetic));
    }
    println!();

    for text in strings {
        println!(
            "{}: {}",
            text,
            text.chars().all(|chr| chr.is_alphabetic() || chr == ' ')
        );
    }
}
text: true
t xt: false
t,xt: false
๐Ÿ˜‡๐Ÿ˜ˆ: false
ฮฉุฃใ…รฑ: true
ืฉืœื•ื: true

text: true
t xt: false
t,xt: false
๐Ÿ˜‡๐Ÿ˜ˆ: false
ฮฉุฃใ…รฑ: true
ืฉืœื•ื: true

text: true
t xt: true
t,xt: false
๐Ÿ˜‡๐Ÿ˜ˆ: false
ฮฉุฃใ…รฑ: true
ืฉืœื•ื: true