...databox.text(来自下面的示例代码)包含以前在程序中填充的大量组合词(域名)。每行有 1 个。在此示例中,它最初看起来像:
thepeople.com
truehistory.com
workhorse.com
whatever.com
neverchange.com
...
下面的代码将数据框中的文本保存到 tlistfiltered.txt,然后搜索 tlistfiltered.txt 以检索包含列表“arr()”中任何项目的所有行,然后用结果填充 listview(lv)。这工作得很好,但结果看起来像:
thepeople.com
truehistory.com
neverchange.com
...
但我需要的是“找到的字符串”(来自 arr()list 是正确的,所以结果是:
thePeople.com
trueHistory.com
neverChange.com
这是代码....
Dim s As String = databox.Text
File.WriteAllText(dloc & "tlistfiltered.txt", s)
databox.Clear()
Dim text2() As String = System.IO.File.ReadAllLines(dloc & "tlistfiltered.txt")
Dim arr() As String = {"people", "history", "change"}
For index1 = 0 To arr.GetUpperBound(0)
Dim YesLines() As String = Array.FindAll(text2, Function(str As String)
Return str.Contains(arr(index1))
End Function).ToArray
databox.Visible = True
For index2 = 0 To YesLines.GetUpperBound(0)
Dim match As String = (YesLines(index2)) & vbCrLf
databox.AppendText(match)
Next
Next
s = databox.Text
File.WriteAllText(dloc & "tlistfilteredfinal.txt", s)
databox.Clear()
domains = (From line In File.ReadAllLines(dloc & "tlistfilteredfinal.txt") Select New ListViewItem(line.Split)).ToArray
lv.Items.Clear()
My.Computer.FileSystem.DeleteFile(dloc & "tlistfiltered.txt")
My.Computer.FileSystem.DeleteFile(dloc & "tlistfilteredfinal.txt")
BackgroundWorker1.RunWorkerAsync()
End Sub
有没有办法即时执行此操作?我已经尝试过 StrConv 等,但它只会将整行转换为正确的大小写。我只希望转换行中包含的“找到”字......
编辑:
在看到@soohoonigan 的回答后,我编辑了
databox.Visible = True
For index2 = 0 To YesLines.GetUpperBound(0)
Dim match As String = (YesLines(index2)) & vbCrLf
databox.AppendText(match)
Next
Next
对此:
databox.Visible = True
For index2 = 0 To YesLines.GetUpperBound(0)
Dim match As String = (YesLines(index2)) & vbCrLf
Dim myTI As System.Globalization.TextInfo = New System.Globalization.CultureInfo("en-US", False).TextInfo
If match.Contains(arr(index1)) Then
match = match.Replace(arr(index1), myTI.ToTitleCase(arr(index1)))
'StrConv(match, vbProperCase)
databox.AppendText(match)
End If
Next
并得到了想要的结果!