count the # of spaces in the string, then add 1. assuming there is only 1 space between words.
2007-03-10 01:04:18
·
answer #1
·
answered by justme 7
·
0⤊
0⤋
The previous answer would be easy to implement, but it will only work if two consecutive words always have exactly one space character in between, and that isn't necessarily the case. Words might be separated by tabs, newlines, multiple spaces, etc.
What you really want to do is identify a list of characters that separate words, then count the number of times a run of characters that aren't in that list is followed by a run of characters that are in that list.
In your list of characters that separate words, you may want to include some punctuation marks as well as whitespace characters, and for coding convenience you may want to include the null character (if your strings are null-terminated, that is).
2007-03-10 14:25:34
·
answer #2
·
answered by Jim R 3
·
0⤊
0⤋