Ignoring numbers that contain alphabetic characters

This commit is contained in:
kdeng00
2023-09-03 20:44:51 -04:00
parent f2de2382e7
commit 001d0c5c17
+16 -3
View File
@@ -25,6 +25,12 @@ pub mod parser {
if let Ok(lines) = self.read_lines(&self.filepath) {
for line in lines {
if let Ok(phonenumber) = line {
let contains_letters = phonenumber.chars().any(|c| c.is_alphabetic());
if contains_letters {
continue;
}
let myobj: SomeObject = SomeObject {
value: phonenumber
};
@@ -111,12 +117,19 @@ pub mod parser {
println!("Unparsed: {}", unparsed);
let mut parsed: String = String::new();
let mychars = unparsed.chars();
for i in 0..unparsed.len() {
let mychar: char = unparsed.chars().nth(i).unwrap();
let mychar_wrap = mychars.clone().nth(i);
if mychar.is_numeric(){
parsed.push(mychar);
if let None = mychar_wrap {
continue;
}
let mychar = mychar_wrap.unwrap();
if mychar.is_numeric() {
parsed.push(mychar.clone());
}
}