Count how many words in each sentence

后端 未结 8 2107
耶瑟儿~
耶瑟儿~ 2021-01-17 05:55

I\'m stuck on how to count how many words are in each sentence, an example of this is: string sentence = \"hello how are you. I am good. that\'s good.\" and ha

8条回答
  •  独厮守ぢ
    2021-01-17 06:18

    As noted in several answers here, look at String functions like Split, Trim, Replace, etc to get you going. All answers here will solve your simple example, but here are some sentences which they may fail to analyse correctly;

    "Hello, how are you?" (no '.' to parse on)
    "That apple costs $1.50."  (a '.' used as a decimal)
    "I   like     whitespace    .    "   
    "Word"  
    

提交回复
热议问题