Public Function Replace3_1(ByVal Expression As String, ByVal Find As String, ByVal Replace As String, Optional ByVal Compare As VbCompareMethod = vbBinaryCompare) As String
Dim l As Long
Dim lenR As Long
Dim p1 As Long
Dim p2 As Long
Dim p21 As Long
Dim s As String
l = Len(Find)
If (l = 0) Then
Replace3_1 = Expression
Exit Function
End If
lenR = Len(Replace)
If (lenR = l) Then
p1 = 1
p2 = InStr(p1, Expression, Find, Compare)
Do While(p2)
Mid$(Expression, p1) = Mid$(Expression, p1, p2 - p1)
Mid$(Expression, p2) = Replace
p1 = p2 + l
p2 = InStr(p1, Expression, Find, Compare)
Loop
Replace3_1 = Expression
Exit Function
ElseIf (lenR > l) Then
s = Space$(Len(Expression) + (Len(Expression) \ l) * (lenR - l))
Else
s = Space$(Len(Expression))
End If
p21 = 1
p1 = 1
p2 = InStr(p1, Expression, Find, Compare)
Do While (p2)
Mid$(s, p21) = Mid$(Expression, p1, p2 - p1)
p21 = p21 + p2 - p1
Mid$(s, p21) = Replace
p21 = p21 + lenR
p1 = p2 + l
p2 = InStr(p1, Expression, Find, Compare)
Loop
Mid$(s, p21) = Mid$(Expression, p1)
p21 = p21 + Len(Mid$(Expression, p1))
s = Left$(s, p21 - 1)
Replace3_1 = s
End Function
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 57