使用 30MB 随机数据文件提取数据真的很慢 [英] Extract data really slow with a 30MB random data file
本文介绍了使用 30MB 随机数据文件提取数据真的很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大约 215,000 行的文本文件.逐行及其随机数据,最后一行我有这个strA123456strB"
I have a text file with about 215,000 lines. line by line and its random data and on the last line I have this "strA123456strB"
在我的电脑上处理这个大约需要 2 秒,但我试图将处理时间减少到几毫秒..有什么建议吗?
to process this its taking about 2 seconds on my computer but I am trying to reduce the processing time to just milliseconds.. any suggestions ?
我这样称呼它
GetStringBetween(RichTextBox.Text, "strA", "strB")
这是vb.net源
Function GetStringBetween(ByVal allData As String, ByVal str1 As String, ByVal str2 As String) As String
Dim foundstr As String = Nothing
Dim i As Integer = allData.ToUpper().IndexOf(str1.ToUpper())
Dim j As Integer
If i > -1 Then
allData = allData.Substring(i + str1.Length)
j = allData.ToUpper().IndexOf(str2.ToUpper())
If j > -1 Then
foundstr = allData.Substring(0, j)
End If
End If
Return foundstr
End Function
推荐答案
以下是使用 Regex 进行搜索的简单示例:
Here is an simple example for between search using Regex:
Dim allData = "nonmatch2_strA_match_strB_nonmatch2"
Dim r = Regex.Match(allData, "strA(.*)strB")
要忽略大小写,请使用 RegexOptions:
To ignore case, use RegexOptions:
Dim r = Regex.Match(allData, "strA(.*)strB", RegexOptions.IgnoreCase)
r =
行执行完毕后,你可以得到它找到的值,如下所示:
After the r =
line finished execution, you can get the value it found like this:
r.Groups(1).Value
这篇关于使用 30MB 随机数据文件提取数据真的很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文