How to split text into words?

前端 未结 7 2341
-上瘾入骨i
-上瘾入骨i 2020-12-04 22:39

How to split text into words?

Example text:

\'Oh, you can\'t help that,\' said the Cat: \'we\'re all mad here. I\'m mad. You\'re mad.\'

7条回答
  •  一生所求
    2020-12-04 23:03

    If you don't want to use a Regex object, you could do something like...

    string mystring="Oh, you can't help that,' said the Cat: 'we're all mad here. I'm mad. You're mad.";
    List words=mystring.Replace(",","").Replace(":","").Replace(".","").Split(" ").ToList();
    

    You'll still have to handle the trailing apostrophe at the end of "that,'"

提交回复
热议问题