vb Replace 实现
今天改一个VB程序时发现程序自带的replace 函数不知什么原因竟然不好用了 所以就自己写了一个玩玩
记录一下
'XGZ '替换字符 Private Function Replace1(ByVal resorce As String, ByVal Tag As String, ByVal value As String) As String Dim ret As String Dim i As Integer Dim j As Integer Dim t As Integer Dim offSet As Integer Dim pos As Integer Dim isTag As Boolean offSet = Len(Tag) '跳跃 Replace1 = "" For i = 1 To Len(resorce) isTag = False If Mid(resorce, i, 1) = Mid(Tag, 1, 1) Then t = i For j = 1 To offSet If Mid(resorce, t, 1) = Mid(Tag, j, 1) Then t = t + 1 End If Next j If t - i = offSet Then '完全匹配 isTag = True i = i + offSet - 1 ' i会自动加一所以在该处减一 End If If Not isTag Then ret = ret & Mid(resorce, i, 1) End If If isTag Then ret = ret & value End If Else ret = ret & Mid(resorce, i, 1) End If Next i Replace1 = ret End Function