mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2024-11-18 02:48:58 +01:00
Aufgaben2_tkruemmel_choenes
This commit is contained in:
parent
860acf0fdc
commit
019babae00
15
aufgaben/sheet2/task3/count.rs
Normal file
15
aufgaben/sheet2/task3/count.rs
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user