當前位置:編程學習大全網 - 源碼下載 - vb使用xmlhttp獲取網頁源碼怎麽用正則表達式過濾和提取標簽內的連接?

vb使用xmlhttp獲取網頁源碼怎麽用正則表達式過濾和提取標簽內的連接?

這個問題挺好解決,這裏貼代碼太多,加QQ 620941幫妳 提取字符給妳寫個函數,不用正則

Function stxtRow(ByVal sStr As String, ByVal nRow As Long, Optional ByVal sP1 As String = vbCrLf, Optional ByVal sP2 As String = vbCrLf) As String

Dim x As Long '循環用

Dim nPoint1 As Long '保存第壹個關鍵點

Dim nPoint2 As Long '保存第二個關鍵點

Dim tnRow As Long '保存默認情況時的 尋找位置號

Dim isDef As Boolean

If sP1 = sP2 Then isDef = True Else isDef = False

For x = 1 To nRow

nPoint1 = InStr(nPoint1 + 1, sStr, sP1)

nPoint2 = InStr(nPoint1 + Len(sP1), sStr, sP2)

'Debug.Print nPoint1, nPoint2

If isDef Then tnRow = nRow - 1 Else tnRow = nRow

If isDef And nPoint2 = 0 And sP2 = vbCrLf Then nPoint2 = Len(sStr) + Len(sP1)

If nPoint1 = 0 Or nPoint2 = 0 Then

If isDef Then

stxtRow = "": Exit Function

'stxtRow = "沒有找到,文件***" & x & "行": Exit Function

Else

stxtRow = "": Exit Function

'stxtRow = "沒有找到,文件***" & x - 1 & "行": Exit Function

End If

End If

If nRow = 1 And isDef And sP2 = vbCrLf Then '如果默認搜頭壹行

stxtRow = Mid(sStr, 1, nPoint1 - 1)

Exit Function

Else '其他情況

If x = tnRow Then

stxtRow = Mid(sStr, nPoint1 + Len(sP1), nPoint2 - nPoint1 - Len(sP1))

Exit Function

End If

End If

Next

End Function

比如字符串s="ksdjfkls我slkjfsd說sdfsdf" 妳要提取我說中間的

stxtRow s,1,"我","說"

這是提取s中 我開頭 說結尾的第壹個字符串,代碼寫的亂但肯定能用

  • 上一篇:VC++樹,單擊節點事件
  • 下一篇:沒有銀行卡能自動存款嗎?
  • copyright 2024編程學習大全網