How to define what a word is for a word count?
I am writing a word count program where a word is defined as any sequence of letters only. Which means, any non-letter characters are used to separate words. Consequently, the sequence “ab12cd3ef gh-ij” contains the “words” ‘ab’, ‘cd’. ‘ef’, ‘gh’ and ‘ij’.
All I want to know is how to define a word this way. I have been trying a number of different ways using the isLetter, isDigit and isWhitespace methods for characters. I am reading my file using bufferedreader and the readline() method. I then convert the file contents to a string with the toString() method and I have also tried to convert it to character array to solve this problem. However, I have yet to figure out how to define a "word" as the brief asks.
Re: How to define what a word is for a word count?
You say you tried isLetter.
I would expect that to work.
You could also look into regex, if that's allowed.