我有一个大约215,000行的文本文件。逐行及其随机数据,在最后一行我有“strA123456strB”
处理它在我的计算机上花了大约2秒但是我试图将处理时间减少到几毫秒..任何建议?
我这样称呼它
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
答案 0 :(得分:1)
以下是使用Regex进行搜索的简单示例:
Dim allData = "nonmatch2_strA_match_strB_nonmatch2"
Dim r = Regex.Match(allData, "strA(.*)strB")
要忽略大小写,请使用RegexOptions:
Dim r = Regex.Match(allData, "strA(.*)strB", RegexOptions.IgnoreCase)
r =
行完成执行后,您可以获得如下所示的值:
r.Groups(1).Value