码迷,mamicode.com
首页 > 其他好文 > 详细

vb Replace 实现

时间:2015-12-11 12:47:44      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

今天改一个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

 

vb Replace 实现

标签:

原文地址:http://www.cnblogs.com/xgzh/p/5038480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!