diff --git a/aufgaben/sheet2/task3/count.rs b/aufgaben/sheet2/task3/count.rs new file mode 100644 index 0000000..52c51bc --- /dev/null +++ b/aufgaben/sheet2/task3/count.rs @@ -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; + }