如何将文本分成的话吗? [英] How to split text into words?

查看:168
本文介绍了如何将文本分成的话吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文本拆分成词



示例文本:




哦,你可没法,猫说:我们都疯了这里。我生气了。 。你疯了




在该行的话是:






  1. 不能

  2. 帮助


  3. 表示,



  4. 我们

  5. 所有


  6. 此处



  7. 您是



解决方案

在空格分割的文本,然后修剪标点符号。

  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:

  1. Oh
  2. you
  3. can't
  4. help
  5. that
  6. said
  7. the
  8. Cat
  9. we're
  10. all
  11. mad
  12. here
  13. I'm
  14. mad
  15. You're
  16. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆