奉献给大家,希望对大家有帮助
Function strCut(strContent, StrStart, StrEnd) As String '通用截取函数
    Dim strHtml, S1, S2 As String
    strHtml = strContent
    On Error Resume Next
    
        S1 = InStr(strHtml, StrStart) + Len(StrStart)
        S2 = InStr(S1, strHtml, StrEnd)
        strCut = Mid(strHtml, S1, S2 - S1)
    
End FunctionPrivate Sub Form_Load()
Dim hunzi1, hunzi2 As String
hunzi1 = "<html><title>this is title</title></html>"
hunzi2 = strCut(hunzi1, "<title>", "</title>")
MsgBox hunzi2
End Sub

解决方案 »

  1.   

    首先,你这个涵数的变量类型定义一踏糊涂.
    其次没有考虑周全,没有考虑到instr()返回0的情况.最后要说的是,你这个涵数如果有人直接COPY去他的项目里.会害死他
    最近比较喜欢噎人,嘿嘿
      

  2.   

    Function strCut(strContent, StrStart, StrEnd) As String '通用截取函数 
        Dim strHtml, S1, S2 As String 
        strHtml = strContent 
        On Error Resume Next 
        
            S1 = InStr(strHtml, StrStart) + Len(StrStart) 
            if S1=0 then ...
            S2 = InStr(S1, strHtml, StrEnd) 
            if S2=0 then ...
            strCut = Mid(strHtml, S1, S2 - S1) 
        
    End Function 
      

  3.   

    Function strCut(strContent as string, StrStart as string, StrEnd as string) As String '通用截取函数 
        Dim strHtml as string
        Dim S1 as long
        Dim S2 As long