News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Replace unwanted characters in a string using Replace

Started by nandagopal, Nov 06, 2008, 04:11 PM

Previous topic - Next topic

nandagopal

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