Leer líneas del archivo, iterar sobre cada línea y cada carácter en esa línea
Necesito leer un archivo, obtener cada línea, iterar sobre cada línea y verificar si esa línea contiene algún carácter de "aeiuo" y si contiene al menos 2 de los caracteres "äüö".
¿Es este código idiomático Rust? ¿Cómo verifico si hay varios caracteres en unString
?
Mi intento hasta ahora con algo de Google y robo de código:
use std::error::Error;
use std::fs::File;
use std::io::BufReader;
use std::io::prelude::*;
use std::path::Path;
fn main() {
// Create a path to the desired file
let path = Path::new("foo.txt");
let display = path.display();
// Open the path in read-only mode, returns `io::Result<File>`
let file = match File::open(&path) {
// The `description` method of `io::Error` returns a string that describes the error
Err(why) => panic!("couldn't open {}: {}", display, Error::description(&why)),
Ok(file) => file,
};
// Collect all lines into a vector
let reader = BufReader::new(file);
let lines: Vec<_> = reader.lines().collect();
for l in lines {
if (l.unwrap().contains("a")) {
println!("here is a");
}
}
}