If I have a string h ell##!omynam493eisj2ohn
( I've removed all whitespaces, digits, punctuation and etc... using regex) to get: hellomynameisjohn
Now what I want to do is for every n
character - so say the minimum length of a word is 4
, so for every 4
characters I want to add in a space and increment count. This is what I got up to so far.
public static int countWords(String original, int minLength){
original = original.replaceAll("[^A-Za-z]","").replaceAll("[0-9]", "");
System.out.println(original);
System.out.println(original.length());
int count = 0;
return count;
}
4 characters = 1 word. Therefore, for every 4 characters add in a space and increment the count by 1. I'm not sure on how I can convert this logic into code. I was thinking about using a for-loop but this is how far I got.
for(int i = 0; i<original.length; i++){
}
Any suggestions?