VB icon

Clean Unwanted Characters From a String

Email
Submitted on: 1/2/2015 6:33:00 PM
By: Tom Harris (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: VB.NET, ASP.NET
Views: 2032
 
     Function to clean all characters but A-Z, a-z, and 0123456789. When I don't use Regular Expressions I use this function to put only the characters I want into a string. It is very useful for password generation. Look up the Dec number on an ASCII chart and use this for many things.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Clean Unwanted Characters From a String
// Description:Function to clean all characters but A-Z, a-z, and 0123456789. When I don't use Regular Expressions I use this function to put only the characters I want into a string. It is very useful for password generation. Look up the Dec number on an ASCII chart and use this for many things.
// By: Tom Harris (from psc cd)
//
// Inputs:The string you want to remove unwanted characters from
//
// Returns:A String with only A-Z, a-z, and 0-9 charactes
//
// Assumes:You will need an ASCII chart to look up the DEC values associated with the ASCII character if you want to modify the specific chars stripped.
http://www.asciitable.com is a good resource.
//**************************************

'Function to clean all characters but A-Z, a-z, and 0123456789 
'When I don't use Regular Expressions I use this function to put 
'only the characters I want into a string. It is very useful 
'for password generation. Look up the Dec number on an ASCII 
'chart and use this for many things. 
 
Public Function CleanString(ByVal strDirty As String) As String 
 
Dim strLen As String 
Dim strCounter As Integer 
Dim strClean As String 
 
strLen = strDirty.Length 
strClean = "" 
 For strCounter = 1 To strLen 
 Select Case Asc(Mid(strDirty, strCounter, 1)) 
   Case 65 To 90 'A-Z 
     strClean = strClean & Mid(strDirty, strCounter, 1) 
   Case 97 To 122 'a-z 
     strClean = strClean & Mid(strDirty, strCounter, 1) 
    Case 48 To 57 ' 0123456789 
     strClean = strClean & Mid(strDirty, strCounter, 1) 
    Case Else 
     'All other characters are stripped out 
 End Select 
 Next 
 
Return LCase(strClean) 
 
End Function 


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.