Aufgaben2_tkruemmel_choenes

This commit is contained in:
Christoph Hönes 2016-11-06 23:49:48 +01:00
parent 860acf0fdc
commit 019babae00

View File

@ -0,0 +1,15 @@
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;
}