Function fstrTran(ByVal sInString As String, _
sFindString As String, _
sReplaceString As String) As String
Dim iSpot As Integer, iCtr As Integer
Dim iCount As Integer
iCount = Len(sInString)
For iCtr = 1 To iCount
iSpot = InStr(1, sInString, sFindString)
If iSpot > 0 Then
sInString = Left(sInString, iSpot - 1) & _
sReplaceString & _
Mid(sInString, iSpot + Len(sFindString))
Else
Exit For
End If
Next
fstrTran = sInString
End Function
tmtony在 2002/04/08 18:24:00 回复-------------------
我也有个例子,在
http://www.office-cn.net/bbs/dispbbs.asp?boardID=3&RootID=1329&ID=1388
里用到.不过也是借用的
Function ReplaceStr(TextIn, SearchStr, Replacement, CompMode As Integer)
Dim WorkText As String, Pointer As Integer
If IsNull(TextIn) Then
ReplaceStr = Null
Else
WorkText = TextIn
Pointer = InStr(1, WorkText, SearchStr, CompMode)
Do While Pointer > 0
WorkText = Left(WorkText, Pointer - 1) & Replacement & Mid(WorkText, Pointer + Len(SearchStr))
Pointer = InStr(Pointer + Len(Replacement), WorkText, SearchStr, CompMode)
Loop
ReplaceStr = WorkText
End If
End Function
大熊在 2002/04/08 18:41:00 回复-------------------
好像基本一样啊,只是觉得你的函数名更好记,但是变量命名就没此人来的规范,可读性也要差一些!两者合并以后,归我用啦!:)
Ps.加个CompMode也很实用。
……