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
Please format your resource.