programmieren-in-rust/aufgaben/sheet2/task3/count.rs
2016-11-06 23:49:48 +01:00

16 lines
352 B
Rust

fn main(){
println!("{}",count("peter",'e'));
}
fn count(word: &str, search: char) -> i32 {
// transformiert string in character array
let letters = word.chars();
let mut result: i32 = 0;
// zähle Vorkommnisse des gesuchten char
for letter in letters {
if letter == search {
result += 1;
}
}
return result;
}