mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2025-01-31 11:48:07 +01:00
16 lines
352 B
Rust
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;
|
||
|
}
|