We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I need to make the sketch search through the string "The unusually quick brown fox jumps over the lazy family dog repeatedly." and make a (println) output report showing the number of occurrences for each vowel (a,e,i,o,u). I made some code, but I got stuck. For example, the println showed 9 for the vowel a even though the vowel a occurs four times in the string. What am I doing wrong? Thanks.
String sentence = "The unusually quick brown fox jumps over the lazy family dog repeatedly."; println(sentence.indexOf("a")); println(sentence.indexOf("e")); println(sentence.indexOf("i")); println(sentence.indexOf("o")); println(sentence.indexOf("u")); noLoop();
Answers
indexOf() gives you the position of the first instance of the search term in the string, starting at zero... So it's not what you want.
You could use matchAll. Since this is obviously homework I'll leave you to figure it out ;)
Pretty much the same question was asked some days ago: https://forum.processing.org/two/discussion/13665/how-to-count-the-repeated-alphabet-in-sketch
The link i posted has some good proposals.