|
|
Title | Replace unwanted characters in a string using Replace |
Keywords | replace, character, remove, unwanted |
Categories | Utilities, Strings |
|
|
Loop through the unwanted characters. For each, use Replace to replace it with a new value. This method has the advantage that it can replace unwanted characters with an empty string or more than one character.
|
|
' Replaces the characters set in strUnwanted as spaces
Public Function ReplaceCharacters(ByRef strText As String, _
ByRef strUnwanted As String, ByRef strRepl As String) _
As String
Dim i As Integer
Dim ch As String
For i = 1 To Len(strUnwanted)
' Replace the i-th unwanted character.
strText = Replace(strText, Mid$(strUnwanted, i, 1), _
strRepl)
Next
ReplaceCharacters = strText
End Function
|
|
|
|
|
|