将字符串与其他字符串列表进行比较 [英] Comparing string with list of other strings

查看:99
本文介绍了将字符串与其他字符串列表进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有一个C#winform应用程序从一些网站废弃数据。 app提取的数据在datagridview控件中暂时保存。该应用程序需要每天运行一次,因此当开始废弃数据时,应用程序会检查重复项,并在发现不在datagridview控件中时添加唯一数据。



现在我的问题是:如何加快将当前字符串与所有其他字符串进行比较的过程?



任何想法,提示等



谢谢,Igor

Hi. I have a C# winform app which scrap data from some site. The data which the app extract, holds temporary in datagridview control. The app need to run once a day so when start to scrap data, the app check for duplicates and add just unique data if it found that is not in the datagridview control.

Now my question is: How I can speed this process of comparing the current string with all other strings?

Any ideas, hints etc.

Thanks, Igor

推荐答案

我不知道但是binairy compairing字符串可能更快,可能是下一个评论者可以帮助你。
I don't know but it might be that binairy compairing strings can be faster, may the next commenters help you with this.


使用
HashSet<string>





如果发现重复,则不会添加。





If duplicates are found it won't be added.

HashSet<string> deduped = new HashSet<string>();

deduped.Add("Test");
deduped.Add("blah");
deduped.Add("Test");

Console.WriteLine(deduped.Count); //outputs 2


实际上我不会将数据保存在某些数据结构中,只是暂时保存在datagridview中。

Datagridview是这样的:



模型位置...... .... ....和其他列...现在如果我有一些当前模型我喜欢比较当前模型的名称与datagridview中具有相同名称的all ...如果模型是bmw x6 ...在datagridview中找到所有bmw x6并将当前与所有其他...进行比较...如果具有相同的名称,但是不同的位置在新行中添加了唯一的模型......这是我关于比​​较的问题...我不喜欢使用一个遍历所有行的for循环...我想知道是否有任何快速方法如何遍历gridview ....
Actually I don't hold my data in some data structure, just temporary hold in datagridview.
Datagridview is like this:

Model Location .... .... .... and othere columns... Now if I have some current model I like to compare the name of the current model with all in the datagridview with the same name... If the model is bmw x6... find all bmw x6 inside the datagridview and compare the current with all other... if have the same name, but different location add in new row the unique model... This is my question about the comparing... I don't like to use one for loop which goes through all rows... I like to know if there is any quick method how to traverse the gridview....


这篇关于将字符串与其他字符串列表进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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