Remove Unwanted Characters

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 = sStrEnd Function
See also  Comparing different methods of testing your Infrastructure-as-Code

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist