- is_alphabetic
- is_alphanumeric
- all
- chars
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