VB5里面实现VB6的InstrRev()和Split()一样的替换函数

类别:VB语言 点击:0 评论:0 推荐:

Private Function split_vb5(ByVal sstr As String, spstr As String) As Variant
Dim starstr, lenstr, cur As Integer
Dim backstr() As String
starstr = InStr(sstr, spstr)
cur = starstr + 1
lenstr = Len(sstr)
ReDim backstr(0)
backstr(0) = Left(sstr, starstr - 1)
For x = starstr + 1 To lenstr
    If Mid(sstr, x, 1) = spstr Then
        ReDim Preserve backstr(UBound(backstr) + 1)
        backstr(UBound(backstr)) = Mid(sstr, cur, x - cur)
        cur = x + 1
        Debug.Print backstr(UBound(backstr))
    End If
Next
split_vb5 = backstr()
End Function

'****************************** 

Private Function InStrRev_vb5(ByVal start As Integer, ByVal str1 As String, ByVal str2 As String)
str1 = revstr(str1)
str2 = revstr(str2)
start=Len(str1)-start
InStrRev_vb5 = Len(str1) - InStr(start, str1, str2)
End Function

Private Function revstr(str As String) As String
Dim x, lenstr As Integer
lenstr = Len(str)
For x = lenstr To 1 Step -1
  revstr = revstr & Mid(str, x, 1)
Next
End Function

本文地址:http://com.8s8s.com/it/it6568.htm