Updated manual word count code to catter for apostrophes in words like John's
This commit is contained in:
@@ -32,10 +32,10 @@ public class WordCounter {
|
|||||||
int characterCounter = 0;
|
int characterCounter = 0;
|
||||||
|
|
||||||
while (characterCounter < stringLength) {
|
while (characterCounter < stringLength) {
|
||||||
if ((Character.isLetter(arg.charAt(characterCounter)) || isAllowedWordPunct(arg.charAt(characterCounter))) && flag == SEPARATOR) {
|
if (isAllowedInWord(arg.charAt(characterCounter)) && flag == SEPARATOR) {
|
||||||
flag = WORD;
|
flag = WORD;
|
||||||
count++;
|
count++;
|
||||||
} else if (!Character.isLetter(arg.charAt(characterCounter))) {
|
} else if (!isAllowedInWord(arg.charAt(characterCounter))) {
|
||||||
flag = SEPARATOR;
|
flag = SEPARATOR;
|
||||||
}
|
}
|
||||||
characterCounter++;
|
characterCounter++;
|
||||||
@@ -43,7 +43,7 @@ public class WordCounter {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAllowedWordPunct(char charAt) {
|
private static boolean isAllowedInWord(char charAt) {
|
||||||
return charAt == '\'';
|
return charAt == '\'' || Character.isLetter(charAt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user