C isalpha
,isdigit
和isalnum
的Rust等价物是什么?
答案 0 :(得分:18)
is_alphabetic, is_digit, is_alphanumeric, is_numeric
正是您要找的。 p>
e.g。 :
fn main() {
println!("1 is a digit {}", '1'.is_digit(10));
println!("f is a hex digit {}", 'f'.is_digit(16));
println!("a is alphabetic {}", 'a'.is_alphabetic());
println!("こis alphabetic {}", 'こ'.is_alphabetic());
println!("a is alphanumeric {}", 'a'.is_alphanumeric());
println!("1 is alphanumeric {}", '1'.is_alphanumeric());
}
返回:
1 is a digit true
f is a hex digit true
a is alphabetic true
こis alphabetic true
a is alphanumeric true
1 is alphanumeric true
Rust standard library docs for chars中详细介绍了它们。