From 019babae00e2b81b509448082ed25dea31458440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20H=C3=B6nes?= Date: Sun, 6 Nov 2016 23:49:48 +0100 Subject: [PATCH] Aufgaben2_tkruemmel_choenes --- aufgaben/sheet2/task3/count.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 aufgaben/sheet2/task3/count.rs 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; + }