VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



String replace function

by Danny Hawkins (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 25th September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

String replace function

Rate String replace function



' Function to replace a string within a string
' srchStr string is the text to look in
' forStr is the string to search for
' repStr is the string to replace any occurences of forStr
*
'
'THIS FUNCTION IS CASE SENSITIVE
'
'   Example:
'           MyString = Replace("Hello world!","Hello","Goodbye")
'
' This would make MyString "Goodbye world!"
'
' D.Hawkins 2002


Public Function Replace(srchStr, forStr, repStr)

If InStr(srchStr, forStr) Then

    Do While InStr(srchStr, forStr)
        place = InStr(srchStr, forStr)
        srchStr = Mid(srchStr, 1, place - 1) & repStr & Mid(srchStr, place + Len(forStr), Len(srchStr))
        Replace = srchStr
    Loop
Else
    Replace = srchStr
End If
End Function

Download this snippet    Add to My Saved Code

String replace function Comments

No comments have been posted about String replace function. Why not be the first to post a comment about String replace function.

Post your comment

Subject:
Message:
0/1000 characters