We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've a set of string it's a music lyric and l want to count how many repeated alphabets like how many A, B,C,D...
but after I searching around I only found the way to count the string not alphabetical letters. is there's anyway to do it?
thank you.
Answers
Have a look at this:
stackoverflow.com/questions/275944/how-do-i-count-the-number-of-occurrences-of-a-char-in-a-string
@benja Thank you man!
you need to convert your lyrics to all upper case first I guess
you then need an Array of int to hold your counts for each letter, e.g. using ascii as an index
https://forum.Processing.org/two/discussion/13750/how-to-make-sketch-look-through-string-make-a-println-showing-number-of-occurrences-of-each-vowel
and have a test case instead of real lyrics
Here, I tried another code from benja's link @Chrisir.
well done
now
letterC[]
holds the count of each letter. well done.now you need to combine the 2 sketches:
make one
setup()
out of the 2setup()
, make onedraw()
(which is easy sincedraw()
here is empty ;-) )(the counting sketch here is a helper sketch for the alphabet sketch)
then when drawing the alphabet in the other sketch read the info from
letterC[]
for that letter and draw it a few times with an offset(edited)
@Chrisir Before going to next step,I have a question. After I combined them together but then it seems like it counted itself repeated 28 times in println.. I don't understand why
check your {} pairs in setup() please
it might be cool to play the song while looking at the screen
you could also like register only the current line in the lyrics.
thus the alphabet would change over the song from line to the next line of the lyrics
declare this int[] letterC before setup since you want to use it in draw() as well