String is alphabetic or alphanumeric


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


examples/strings/is-alphabetic/src/main.rs
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