Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Mar 19, 1999

Remove Unwanted Characters

When working with or fixing Access databases and Excel spreadsheets created by users at my company, I often have to use their strings from the table or spreadsheet to save the resultant fixed file. The problem is that the strings they use often contain illegal file-name characters. This function strips away the illegal characters and replaces them with an underscore character. To use the character, call the function, passing the string you want checked and stripped:
 
Public Function fConvert(ByVal sStr As String) As String
	Dim i As Integer
	Dim sBadChar As String

	' List all illegal/unwanted characters
	sBadChar = "/<>?\|*:'"

	' Loop through all the characters of the string
	' checking whether each is an illegal character
	For i = 1 To Len(sStr)
		If InStr(sBadChar, Mid(sStr, i, 1)) Then
			Mid(sStr, i, 1) = "_"
		End If
	Next I
	fConvert = sStr
End Function
Grant Porteous
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date