Skip to content

Instantly share code, notes, and snippets.

@tahadostifam
Last active October 25, 2024 11:14
Show Gist options
  • Select an option

  • Save tahadostifam/daebb7149d65c33d9d486baac5568a3c to your computer and use it in GitHub Desktop.

Select an option

Save tahadostifam/daebb7149d65c33d9d486baac5568a3c to your computer and use it in GitHub Desktop.
Is the given input number? in Rust =/
fn is_number(src: String) -> bool {
let c: u32 = src.chars().nth(0).unwrap() as u32;
let bounds = ('1' as u32, '9' as u32);
return c >= bounds.0 && c <= bounds.1;
}
fn is_alpha(src: String) -> bool {
return src.to_lowercase() != src.to_uppercase();
}
fn main() {
let code = String::from("a");
let result = is_number(code.clone());
println!("Result-> {}", result);
let result = is_alpha(code.clone());
println!("Result-> {}", result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment