現在、特定の Web ページからデータを取得するアプリケーションを開発しようとしています。
この Web ページに次のコンテンツがあるとします。
<needle1>HAYSTACK 1<needle2>
<needle1>HAYSTACK 2<needle2>
<needle1>HAYSTACK 3<needle2>
<needle1>HAYSTACK 4<needle2>
<needle1>HAYSTACK 5<needle2>
そして、次の VB.NET コードがあります。
Dim webClient As New System.Net.WebClient
Dim FullPage As String = webClient.DownloadString("PAGE URL HERE")
Dim ExtractedInfo As String = GetBetween(FullPage, "<needle1>", "<needle2>")
GetBetween は次の関数です。
Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String) As String
Dim istart As Integer = InStr(haystack, needle)
If istart > 0 Then
Dim istop As Integer = InStr(istart, haystack, needle_two)
If istop > 0 Then
Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
Return value
End If
End If
Return Nothing
End Function
上記のコードを使用すると、ExtractedInfo は常に "HAYSTACK 1" と等しくなります。これは、最初に検出されたものから常に干し草の山を取得するためです。
私の質問は次のとおりです。2番目、3番目、4番目などの出現を探すために、ある種の配列のようにExtractedInfoをセットアップする方法。
何かのようなもの:
ExtractedInfo(1) = HAYSTACK 1
ExtractedInfo(2) = HAYSTACK 2
前もって感謝します!