如何将文本分成的话吗? [英] How to split text into words?
本文介绍了如何将文本分成的话吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将文本拆分成词
示例文本:
哦,你可没法,猫说:我们都疯了这里。我生气了。 。你疯了
块引用>
在该行的话是:
- 哦
- 您
- 不能
- 帮助
- 是
- 表示,
- 在
- 猫
- 我们
- 所有
- 狂
- 此处
- 我
- 狂
- 您是
- 狂
解决方案在空格分割的文本,然后修剪标点符号。
VAR文本=哦,你可没法,猫说:我们这儿全都是疯的,我是疯的,你是疯了。 ';
变种标点符号= text.Where(Char.IsPunctuation).Distinct()ToArray的();
VAR字= text.Split()选择(X => x.Trim(标点符号))。
同意恰与例子。
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.'
The words in that line are:
- Oh
- you
- can't
- help
- that
- said
- the
- Cat
- we're
- all
- mad
- here
- I'm
- mad
- You're
- mad
解决方案Split text on whitespace, then trim punctuation.
var text = "'Oh, you can't help that,' said the Cat: 'we're all mad here. I'm mad. You're mad.'"; var punctuation = text.Where(Char.IsPunctuation).Distinct().ToArray(); var words = text.Split().Select(x => x.Trim(punctuation));
Agrees exactly with example.
这篇关于如何将文本分成的话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文