VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find and replace one string with another.

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

Find and replace one string with another.

Rate Find and replace one string with another.



        tmpString1 = SourceString
        Do Until vFixed
            tmpString2 = tmpString1
            tmpString1 = ReplaceFirstInstance(tmpString1, SearchString,ReplaceString)
            If tmpString1 = tmpString2 Then vFixed = True
        Loop
        FindReplace = tmpString1
    End Function

    Function ReplaceFirstInstance(SourceString, SearchString, ReplaceString)
        FoundLoc = InStr(1, SourceString, SearchString)
        If FoundLoc <> 0 Then
                ReplaceFirstInstance = Left(SourceString, FoundLoc - 1) & _
                ReplaceString & Right(SourceString, _
                Len(SourceString) - (FoundLoc - 1) - Len(SearchString))
        Else
            ReplaceFirstInstance = SourceString
        End If
    End Function

Download this snippet    Add to My Saved Code

Find and replace one string with another. Comments

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

Post your comment

Subject:
Message:
0/1000 characters