それが最善の解決策だ場合、あなたのポストから言うことは容易ではないが、一つの解決策は、単語Start
を含むすべての行を検索しregular expressionsを使用することです:
^.*\bStart\b.*$
は、その行全体が一致しますどこでも完全な単語Start
が含まれています。単語の一部としてStart
を拒否します。たとえば、Starting
は一致しません(つまり、単語境界アンカーの意味は\b
です)。 VB.NETでこれを使用するには
:
Dim RegexObj As New Regex(
"^ # Start of line" & chr(10) & _
".* # Any number of characters (anything except newlines)" & chr(10) & _
"\b # Word boundary" & chr(10) & _
"Start # ""Start""" & chr(10) & _
"\b # Word boundary" & chr(10) & _
".* # Any number of characters (anything except newlines)" & chr(10) & _
"$ # End of line",
RegexOptions.Multiline Or RegexOptions.IgnorePatternWhitespace)
AllMatchResults = RegexObj.Matches(vrDisplay)
If AllMatchResults.Count > 0 Then
' Access individual matches using AllMatchResults.Item[]
Else
' Match attempt failed
End If
おそらく動作しますが、組み込みのStreamReader.ReadLine()はファイル全体を含む文字列で正規表現を実行するよりも高速で、必要なメモリが少なくなります。 – Reinderien
@Reinderien:まったく。しかし、おそらく彼は一度にメモリ内のファイル全体を必要とするでしょう。誰が教えてくれる? –
ティムは正しいです。私はすぐにメモリ内のファイル全体を必要とします。 –