Count how many words in each sentence

后端 未结 8 2037
耶瑟儿~
耶瑟儿~ 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:20

    string text = "hello how are you. I am good. that's good.";
    string[] sentences = s.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
    IEnumerable wordsPerSentence = sentences.Select(s => s.Trim().Split(' ').Length);
    

提交回复
热议问题