|
weAscend.com
Function fReplace(strString As String, _
strOld As String, _
strNew As String) As String
'***************************************
'Copyright (c) weAscend Technologies
'Contact via: www.weAscend.com
'
'strString is the string that contains
'characters to be replaced
'
'strOld is the characters to be replaced
'
'strNew is the new characters
'***************************************
Dim strTemp As String
Dim intPos As Integer
Dim intLen As Integer
Dim intLenOld As Integer
Dim intNext As Integer
On Error GoTo Error_Handler
If (InStr(1, strString, strOld) = -1) _
Then GoTo No_Replace
strTemp = ""
intPos = 1
intLen = Len(strString)
intLenOld = Len(strOld)
intNext = 0
Do Until intPos >= intLen + 1
intNext = InStr(intPos, strString, strOld) - intPos
Select Case InStr(intPos, strString, strOld)
Case 0
strTemp = strTemp & Mid(strString, intPos)
intPos = intLen + 1
Case Else
strTemp = strTemp & _
Mid(strString, intPos, intNext) & strNew
intPos = intPos + intNext + intLenOld
End Select
Loop
fReplace = strTemp
Exit_Function:
Exit Function
No_Replace:
fReplace = strString
GoTo Exit_Function
Error_Handler:
fReplace = "#Error#"
GoTo Exit_Function
End Function
Contact
Us |