I need to count the number of words, and I guess the right way to do this is by calculating the number of times that the previous character in the string is not a letter (i.e. other characters), because this should assume that there will be colons, spaces, tabs and others in the string signs. So my first idea was to scroll through each character and count how many times you did not get the letter of the alphabet
for(int i = 0; i < string.length(); i++) {
for(int j = 0; i < alphabets.length(); j++) {
if (string.charAt(i-1) == alphabets.charAt(j)) {
counter++;
}
}
}
However, because of this, I always get an array from outside. So, I need a little help or another way that can really be more effective. I was thinking of using Matches only for [a-zA-z], but I'm not sure how to handle the char to be comparable to the string when counting how many times this happens.
thank