What is the syntax to replace a string with another?

Replace(String, find, replacewith, start, count, compare)
'string - string that will be searched; mandatory parameter
'find - string part that will be replaced; mandatory parameter
'replacewith - string part that will be inserted; mandatory parameter
'start – integer specifying the starting position of search; optional parameter where default is 1
'count - integer specifying number of times the replacement has to be performed; optional parameter
'compare - integer specifying the comparison method: 0 for binary, 1 for textual; optional parameter
'examples
Dim sentence As String
sentence = "The red fox"
MsgBox (Replace(sentence, "red", "blue", 1, 1)) 'The blue fox
MsgBox (Replace(sentence, "fox", "panda", 1)) 'The red panda
MsgBox (Replace(sentence, "fox", "panda", 9)) 'panda
MsgBox (Replace(sentence, "The", "My")) 'My red fox

 

Advertisements