Question How to remove all special characters from string in vb.net?

Posted by msivasakthi on January 13, 2009

hi all, How to remove or replace all special characters(!@#$%^&*(){}[]""_+<>?/) from string in vb .net? the example string is like.... [read more]

Rating

4/5

Reviews

This is an answer to a forum thread which includes an example function written in VB.NET to remove special characters from a String.

Posted by HivelocityDD
"You can try the following function


Public Function strip(ByVal des As String)
Dim strorigFileName As String
Dim intCounter As Integer
Dim arrSpecialChar() As String = {".", ",", "", ":", "?", """", "/", "{", "[", "}", "]", "`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", "|", " ", "\"}
strorigFileName = des
intCounter = 0
Dim i As Integer
For i = 0 To arrSpecialChar.Length - 1

Do Until intCounter = 29
des = Replace(strorigFileName, arrSpecialChar(i), "")
intCounter = intCounter + 1
strorigFileName = des
Loop
intCounter = 0
Next
Return strorigFileName

End Function
"

Related:
VBScript String Clean Functions
3 different methods to remove or replace special characters from a string.
By GeorgeH on July 31, 2011 3:16AM

Submit a review:

Login required.