当前位置:编程学习 > VB >>

查找替换所选字符

 

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

补充:软件开发 , Vb ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,