搜索txt文件的最快方法? [英] Fastest way to search through txt file?

查看:144
本文介绍了搜索txt文件的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在很长一段时间没有发现任何问题,但我来到了

点,我真的需要寻求帮助。


我需要创建一个应用程序,它将搜索.txt日志

文件并找到所有来自hotmail发送电子邮件的行。


所有这些电子邮件都需要打印到表单上的列表框。


您将在下面看到的代码问题,是否需要很长时间才能

搜索。仅10mb文件就需要近2分钟。而且我需要处理1-2 GB的文件。
需要处理1-2 GB的文件。因为这只是中间步骤而且

程序有更多的功能,我不能等待这个

长。


现在我的搜索方式是,我将每一行加载到

隐藏的richtextbox中并使用其查找命令查看是否有任何

出现的hotmail .com,如果它是我在列表框中显示行。


这个过程非常慢。


如何提取该电子邮件地址出了问题,这是另一个

的故事,有人知道vb.net的任何好的电子邮件解析器吗?


有人可以查看代码和告诉我我做错了什么?为什么

这么慢?

非常感谢。


vjay

Dim oFile As System.IO.File

Dim oRead As System.IO.StreamReader

Dim linein As String

Dim Result As Integer

Dim count As Integer


oRead = oFile.OpenText(log.txt)


而oRead.Peek<> -1

count = count + 1

linein = oRead.ReadLine()

RichTextBox1.Text = linein

''StatusBar1.Text = count.ToString


结果= RichTextBox1.Find(" hotmail.com",

RichTextBoxFinds.MatchCase)

如果结果<> -1然后

ListBox2.Items.Add(linein)

结束如果

结束时

oRead.Close ()


发布通过Usenet.com高级Usenet新闻组服务

------------------- ---------------------------------------

** SPEED **保留**完成**匿名**

------------------------------- ---------------------------
http://www.usenet.com

推荐答案

嗨Vjay,


我想半年前我在这个新闻组做了一个测试是什么是

在文本文件中进行查找的最快方法(代码支持不同的

人)。


这个代码得到了Jon的名字支持。


(计算多少次单词是在文本中,你需要的地方,就是这个例行程序每次iStart当然是

)。


\\
公共函数Test2(ByVal strInput As String,ByVal strDelimiter _

As String)As Int32''Jon(string)

Dim iStart As Int32,iCount As Int32,iResult As Int32

iStart = 1

iCount = 0

Do

iResult = InStr(iStart,strInput,strDelimiter)

如果iResult = 0则退出Do

iCount + = 1

iStart = iResult + 1

循环

返回iCount

结束功能

///

如果分隔符是一个字符串(不带字符),这绝对是最快的。


我希望你可以使用它,如果你仍然需要帮助来实现这一点

你的解决方案再说一次吗?


Cor
Hi Vjay,

I think about an half a year ago I did a test in this newsgroup what was
the fastest method to do a find in a textfile (code supported by different
persons).

This code was supported by someone who had as firstname Jon.

(It counts how many time a word is in a text, you needs the places, that is
of course everytime iStart in this routine ).

\\\
Public Function Test2(ByVal strInput As String, ByVal strDelimiter _
As String) As Int32 ''Jon (string)
Dim iStart As Int32, iCount As Int32, iResult As Int32
iStart = 1
iCount = 0
Do
iResult = InStr(iStart, strInput, strDelimiter)
If iResult = 0 Then Exit Do
iCount += 1
iStart = iResult + 1
Loop
Return iCount
End Function
///
This was absolute the fastest if the delimiter is a string (not with a char)

I hope that you can use it, if you still needs help to implement this in
your solution tell it than again?

Cor


Cor,

谢谢你但我不需要数数,我需要找到一个单词并显示

它在我的列表框中出现的行。

请告诉我是否你知道我怎么能修改它以便你的快速

脚本做我需要的。

非常感谢你的帮助。

发布通过Usenet.com Premium Usenet新闻组服务
--------------------------------------------- -------------

**速度**保留**完成**匿名**

------- -------------------------------------------------- -
http://www.usenet.com
Cor,
thank you but I don''t need to count, I need to find a word and display
the line in which it occured in my listbox.
Please let me know if you know how I could amend it so your fast
script does what I need.
Thanks a lot for your help.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


你应该尝试将文件加载到部分(如果你关心内存)和

使用RegularExpressions处理它。


使用文件流对象可能对内存更好,我不是很确定...


我认为你会发现RegEx正是你想要的,而且非常好/>
快。

" Vjay77" < VJ ******** @ Hotmail的双点com.no-spam.invalid>在消息中写道

新闻:40 ******** @ Usenet.com ...
You should try loading a file into parts (if you concerned about memory) and
process it using RegularExpressions.

Using a filestream object may be better for memory, I''m not real sure...

I think you will find RegEx is exactly what your looking for, and its VERY
fast.
"Vjay77" <vj********@hotmail-dot-com.no-spam.invalid> wrote in message
news:40********@Usenet.com...
Cor,
谢谢你,但我不知道需要数一下,我需要找一个单词并显示它在我的列表框中出现的行。
如果你知道如何修改它,请告诉我你的快速
脚本做我需要的。
非常感谢你的帮助。

发布通过Usenet.com Premium Usenet新闻组服务
------------ ----------------------------------------------
**速度**保留**完成**匿名**
-------------------------------- --------------------------
http://www.usenet.com



这篇关于搜索txt文件的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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