How can I make sure my function is not overcounting the number of words?
I’m writing a function to count the number of words in a user-inputted string of text. Currently I’ve set it up for word_count
to increment every time it hits a space or punctuation mark, but I know that’s not right as it’ll increment twice when it gets to the end of a sentence. It’ll also increment when it hits an apostrophe or hyphen within a word.
How can I make sure my function is not overcounting the number of words?
I’m writing a function to count the number of words in a user-inputted string of text. Currently I’ve set it up for word_count
to increment every time it hits a space or punctuation mark, but I know that’s not right as it’ll increment twice when it gets to the end of a sentence. It’ll also increment when it hits an apostrophe or hyphen within a word.