Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleReplace unwanted characters in a string using Replace
Keywordsreplace, character, remove, unwanted
CategoriesUtilities, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated