Stripping out punctuation marks

Discussion in 'ASP .Net' started by dew, Feb 6, 2006.

  1. dew

    dew Guest

    Is there an easy way to edit a string so that only alphabetical characters
    and numbers are allowed? Thanks for your help.
    dew, Feb 6, 2006
    #1
    1. Advertising

  2. Try this function:

    Public Function Removes(ByVal mystring As String) As String

    Dim newstring As String

    For Each character As Char In mystring

    If Not Char.IsPunctuation(character) Then newstring &= character

    Next

    Return newstring

    End Function


    This basically loops through the string and tests whether each character is
    punctuation. If it is not, it appends it to a new string. You can use the
    same technique for the other Is... methods of the Char type. You can also
    use the Replace method to replace all instances of a specific character with
    a zero-length String as in the following:

    mystring.Replace("."c,"")

    The lower-case c in the code tells VB.NET to interpret the String as a Char.
    Try whichever one of these works best for you, if you need more help feel
    free to ask. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "dew" <> wrote in message
    news:...
    > Is there an easy way to edit a string so that only alphabetical characters
    > and numbers are allowed? Thanks for your help.
    >
    Nathan Sokalski, Feb 7, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelly
    Replies:
    1
    Views:
    413
    The Durban Towel
    Apr 28, 2004
  2. =?Utf-8?B?THU=?=
    Replies:
    4
    Views:
    1,463
    Joerg Jooss
    Sep 2, 2005
  3. Replies:
    2
    Views:
    430
    Peter Koch Larsen
    Apr 13, 2005
  4. Replies:
    2
    Views:
    329
    Peter Koch Larsen
    Apr 13, 2005
  5. Anat
    Replies:
    2
    Views:
    230
    Lasse Reichstein Nielsen
    May 25, 2006
Loading...

Share This Page