如何在VB.NET中删除句子中的重复单词 [英] How do you remove duplicate words in a Sentence in VB.NET

查看:87
本文介绍了如何在VB.NET中删除句子中的重复单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的字典的第二列中的每个原始文件中添加了一个空格,该空格由此分隔:|



现在,如何在VB.NET中删除句子中的重复项:





aaa和撰写论文的最佳方式是购买研究论文。



购买最佳购买地点纸张将上线。






好​​的,来自的单词来自ListView后执行自动完成。 ListView提供了Dictionary的建议。当您单击某个项目时,它会将其添加到当前行的RichTextBox。

I have added a space in every raw on the second column of my dictionary which is delimited by this: |

Now, how can I remove the duplicates in a sentence in VB.NET:


a a a and the best way to write write a paper is to buy a research paper.

the the best place to buy buy a paper is to go go online.



OK, where the words are coming from is from a ListView after performing an Autocompletion. The ListView provides the suggestions from the Dictionary. When you click on an item, it adds it to a RichTextBox on the current line.

推荐答案

此问题基于重复项及其位置。有很多方法可以删除重复项但位置因素会改变一些事情。



你必须有某种形式的循环或聚合函数:

This problem is based around duplicates AND their position. There are many ways to remove duplicates but the position factor changes things.

You will have to have some form of loop or aggregate function:
const string input = @"a a a and the best way to write write a paper is to buy a research paper.

the the best place to buy buy a paper is to go go online."

string RemoveDuplicateWords(){
  List<string> resultRows = new List<string>();

  string[] rows = input.split('\n');

  foreach(var row in rows){

    resultRows.Add(row.Split(' ').Aggregate((current,next)=>current.Split(' ').Last==next?current:current+' '+next));
  } 
  
  return string.Join("\n",resultRows);
  
}
</string></string>







一些问题:



这确实有一些语法问题可能会出现两个单词,并且应该一起出现:



我的兄弟说他没有吃任何东西,但实际上他吃过饭。 < -correct



确实,那个男人在那句话中使用的那个是错的。 < - 也正确第一个和第四个(和第六个)'是相对代词,第二个和第五个'是形容词,第三个'那个'是名词。前一句中的所有内容都是名词。

它可以写得更好:

确实,那个男人在那句话中使用的'那个'是错的。 < - ''被允许澄清不寻常或不确定的名词。另一个'那就是我们必须假设有几个人使用了几个'而且我们指出了不正确的那个。





现在:如果有人指出使用了我错误使用的那个这个词,那么这个帖子可能会变得如此递归,以至于宇宙会自行崩溃。

你已经被警告了!



更新:



还有VB#^ _ ^#



使用 http:// codeconverter转换。 sharpdevelop.net/SnippetConverter.aspx [ ^ ]




Some issues:

This does have some grammatical issues where two words may, and should appear together:

My Brother said that he hadn't had anything to eat, but in fact he had had dinner. <-correct

It is true that that that that that man used in that sentence is wrong. <- also correct The first and fourth (and sixth) 'that's are relative pronouns, the second and fifth 'that's are adjectives and the third 'that' is a noun. All 'that's in the previous sentence are nouns.
It can be written better:
It is true that that 'that' that that man used in that sentence is wrong. <- '' is allowed to clarify uncommon or uncertain nouns. The other 'that's stand as we have to assume that several men used several 'that's and we are pointing out the incorrect one.


Now: If anyone points out a use of the word 'that' that I have used incorrectly, this post might become so recursively meta that the universe will collapse in on itself.
YOU HAVE BEEN WARNED!

UPDATE:

And also in VB #^_^#

Converted with http://codeconverter.sharpdevelop.net/SnippetConverter.aspx[^]

	Const  input As String = "a a a and the best way to write write a paper is to buy a research paper." & vbCr & vbLf & " " & vbCr & vbLf & "the the best place to buy buy a paper is to go go online."

Public Function RemoveDuplicateWords() As String

	Dim resultRows As New List(Of String)()

	Dim rows As String() = input.Split(ControlChars.Lf)

	For Each row As var In rows

		resultRows.Add(row.Split(" "C).Aggregate(Function(current, [next]) If(current.Split(" "C).Last = [next], current, current + " "C + [next])))
	Next

	Return String.Join(vbLf, resultRows)

End Function


这篇关于如何在VB.NET中删除句子中的重复单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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