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
Keywordsreplace, character, remove, unwanted
CategoriesUtilities, Strings
 
By Zia Abas.

Loop through the characters. For each, see if it is in a string containing the unwanted characters. If a character is unwanted, replace it with the replacement character.

 
' Replaces the characters set in strUnwanted as spaces
Public Function RemoveCharacters(ByRef strText As String, _
    ByRef strUnwanted As String) As String
Dim currLoc As Integer
Dim StringLength As Integer
Dim tmpChar As String

    StringLength = Len(strText)
    For currLoc = 1 To StringLength
        tmpChar = Mid(strText, currLoc, 1)
        If InStr(strUnwanted, tmpChar) Then
            ' Replace with a space
            Mid(strText, currLoc, 1) = " "
        End If
    Next

    RemoveCharacters = strText
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated