Last active
October 25, 2024 11:14
-
-
Save tahadostifam/daebb7149d65c33d9d486baac5568a3c to your computer and use it in GitHub Desktop.
Is the given input number? in Rust =/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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