Exclude Desired Charectors From The String

Exclude Desired Charectors From The String



While Developing many time we require a function to manipulate or filter strings. I am going to provide the solution which i have made for our projects.
Given function is capable to remove special characters from passed string.

It can also be used according to requirments of project by including or removing this line..

arrexclude.Add(--Symbol To Filter--)
--

Private Function GetStringwithoutSpecificCharectors(ByVal TestString As String) As String
Dim strTestString As String = ""
Dim i As Integer = 0
Try
TestString = TestString.Replace(" ", "_")
TestString = "[" & TestString & "]"
Dim arrexclude As New ArrayList
arrexclude.Add(".")
arrexclude.Add(">")
arrexclude.Add("<")
arrexclude.Add("@")
arrexclude.Add("%")
arrexclude.Add("^")
arrexclude.Add("&")
arrexclude.Add("(")
arrexclude.Add(")")
arrexclude.Add("!")
arrexclude.Add("~")
arrexclude.Add("'")
arrexclude.Add(",")
arrexclude.Add(";")
arrexclude.Add("|")
arrexclude.Add("/")
arrexclude.Add("+")
arrexclude.Add("}")
arrexclude.Add("{")
arrexclude.Add("?")
arrexclude.Add("\")
arrexclude.Add(":")
For i = 0 To TestString.Length - 1
If arrexclude.IndexOf(TestString(i).ToString()) < 0 Then
strTestString = strTestString & TestString(i).ToString()
End If
Next
Catch ex As Exception

End Try
Return strTestString
End Function

--
Best of Luck


Comments

Author: ABitSmart08 Dec 2009 Member Level: Gold   Points : 0

Please format your resource.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: