`

[转] ACCESS 97 类似 replace 及 split 函數

阅读更多
Function replace(ByVal sstr As String, ByVal stag As String, ByVal srep As StringAs String
    
Dim l1, l2, l3, x, i As Long
    
Dim st As String
    x 
= InStr(sstr, stag)
    
If x < 1 Then
        
replace = sstr
        
Exit Function
    
End If
    st 
= sstr
    l1 
= Len(sstr)
    l2 
= Len(stag)
    l3 
= Len(srep)
    
For i = 0 To l1
        st 
= Left(st, x - 1& srep & Right(st, Len(st) - x - l2 + 1)
        x 
= InStr(x + l3, st, stag)
        
If x < 1 Then Exit For
    
Next
    
replace = st
End Function


Function split(ByVal sstr As String, ByVal spstr As StringAs Variant
Dim star, lenstr, lensp, cur As Integer
Dim backstr() As String
Dim i As Integer
ReDim backstr(0)
lenstr 
= Len(sstr)
lensp 
= Len(spstr)
star 
= InStr(sstr, spstr)
If star < 1 Then
    backstr(
0= sstr
    
split = backstr()
    
Exit Function
End If
backstr(
0= Left(sstr, star - 1)
cur 
= star + lensp
For i = star + lensp To lenstr
    star 
= InStr(star + lensp, sstr, spstr)
    
If star > 0 Then
        
ReDim Preserve backstr(UBound(backstr) + 1)
        backstr(
UBound(backstr)) = Mid(sstr, cur, star - cur)
        cur 
= star + lensp
    
Else
        
Exit For
    
End If
Next
ReDim Preserve backstr(UBound(backstr) + 1)
backstr(
UBound(backstr)) = Mid(sstr, cur, lenstr - cur + 1)
split = backstr()
End Function 


temptation 2007-09-07 14:22 发表评论
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics