把符串中的一子串替换为另一子串
2008-02-23 06:55:33来源:互联网 阅读 ()
Public Function FastReplace(SSrch$, SFind$, SRepl$) As String
Dim Src() As Byte, Dst() As Byte, R() As Byte, F() As Byte
Dim LenF&, LenR&, LenDst&, i&, j&, OutPos&
Const ChunkSize& = 4096
If SSrch = "" Or SFind = "" Then Exit Function
Src = SSrch: F = SFind: R = SRepl
LenF = UBound(F): LenR = UBound(R)
LenDst = ChunkSize: ReDim Dst(0 To LenDst - 1)
For i = 0 To UBound(Src) Step 2
For j = 0 To LenF Step 2
If Src(i j) <> F(j) Then Exit For
Next j
If j > LenF Then 'Found
For j = 0 To LenR Step 2
If OutPos >= LenDst Then
LenDst = LenDst ChunkSize
ReDim Preserve Dst(0 To LenDst)
End If
Dst(OutPos) = R(j): OutPos = OutPos 2
Next j
i = i LenF - 1
Else
If OutPos >= LenDst Then
LenDst = LenDst ChunkSize
ReDim Preserve Dst(0 To LenDst)
End If
Dst(OutPos) = Src(i): OutPos = OutPos 2
End If
Next i
ReDim Preserve Dst(0 To OutPos - 2): SSrch = Dst
FastReplace = SSrch$
End Function
方法二:
' SearchLine is input, SearchFor is what to search for, ReplaceWith is the replacement
Function sReplace(SearchLine As String, SearchFor As String, ReplaceWith As String)
Dim vSearchLine As String, found As Integer
found = InStr(SearchLine, SearchFor): vSearchLine = SearchLine
If found <> 0 Then
vSearchLine = ""
If found > 1 Then vSearchLine = Left(SearchLine, found - 1)
vSearchLine = vSearchLine ReplaceWith
If found Len(SearchFor) - 1 < Len(SearchLine) Then _
vSearchLine = vSearchLine Right$(SearchLine, Len(SearchLine) - found - Len(SearchFor) 1)
End If
sReplace = vSearchLine
End Function
上一篇: 把数字转成英文字
下一篇: 切分字符串
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:一些字符串操作的问题和回答
下一篇:用VB实现鼠标的隐藏
- 把符串中的一子串替换为另一子串 2018-06-17
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash