VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Search and replace a string within another

by Anonymous (267 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Thu 17th December 1998
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Search and replace a string within another

Rate Search and replace a string within another




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

Download this snippet    Add to My Saved Code

Search and replace a string within another Comments

No comments have been posted about Search and replace a string within another. Why not be the first to post a comment about Search and replace a string within another.

Post your comment

Subject:
Message:
0/1000 characters