Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Stripping out punctuation marks

Reply
Thread Tools

Stripping out punctuation marks

 
 
dew
Guest
Posts: n/a
 
      02-06-2006
Is there an easy way to edit a string so that only alphabetical characters
and numbers are allowed? Thanks for your help.


 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      02-07-2006
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.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

"dew" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there an easy way to edit a string so that only alphabetical characters
> and numbers are allowed? Thanks for your help.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String splitting without loosing punctuation marks Anat Javascript 2 05-25-2006 11:47 AM
not dust marks - water marks! pshaw@emmet.com Digital Photography 0 04-14-2005 05:53 AM
Lexicographic ordering of punctuation marks masood.iqbal@lycos.com C++ 2 04-13-2005 09:20 AM
Lexicographic ordering of punctuation marks masood.iqbal@lycos.com C Programming 2 04-13-2005 09:20 AM
Stripping out email addresses Kelly Perl 1 04-28-2004 09:56 PM



Advertisments