VB.net第二个字符串找到了getbetween

时间:2012-11-23 23:31:29

标签: vb.net substring

我有一个函数可以给我两个单词之间的文字:

Private Shared Function GetBetween(ByRef strSource As String, ByRef strStart As String, ByRef strEnd As String, Optional ByRef startPos As Integer = 0) As String
    Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
    Dim strResult As String
    strResult = String.Empty
    iPos = strSource.IndexOf(strStart, startPos)
    iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
    If iPos <> -1 AndAlso iEnd <> -1 Then
        strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
    End If
    Return strResult
End Function

所以我的HTML代码是:

<div class="upper-right-section">
            <div class="header-stats">


    <div class="stat-entry">
        <span class="stat-value">48998</span>
  <span class="stat-name">iscritti</span>

    </div>



    <div class="stat-entry">
        <span class="stat-value">22760801</span>
  <span class="stat-name">visualizzazioni video</span>

    </div>

  </div>

          <span class="valign-shim"></span>
        </div>

我有两次<span class="stat-value">我希望获得第二场比赛的价值,我该怎么办?谢谢,matteo。

1 个答案:

答案 0 :(得分:1)

对于一般的html解析,HAP或CSQuery很棒,但是如果这是程序中的一个独立案例,并且您确信html源将保持不变,则可以使用以下内容:

Dim value As String = Split(Split(theHtmlStringHere, "<span class=""stat-value"">")(2), "</span>")(0)