replace all caracters in a string that are not one of 0-9 or a-z or A-Z with a space...
-
hi all, How would one go about replacing a character in a string with a space where the character is not in the range of a-z or A-Z or 0-9 ??? the following Code did not have the planned outcome...
Dim cleanString As String = [String].Empty Dim reg As New Text.RegularExpressions.Regex("[A-Z]|[a-z]|[0-9]") Dim coll As Text.RegularExpressions.MatchCollection = reg.Matches(LineText, ) For i As Integer = 0 To LineText.Length - 1 MsgBox(coll(i).Value) If (coll(i).Value = [String].Empty) Then cleanString = cleanString + " " Else cleanString = cleanString + coll(i).Value End If Next
the result was not pritty.... it removed spaces as well... how do i keep spaces and replace (NOT REMOVE) other characters with a space??? Thank you in advance."Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
-
hi all, How would one go about replacing a character in a string with a space where the character is not in the range of a-z or A-Z or 0-9 ??? the following Code did not have the planned outcome...
Dim cleanString As String = [String].Empty Dim reg As New Text.RegularExpressions.Regex("[A-Z]|[a-z]|[0-9]") Dim coll As Text.RegularExpressions.MatchCollection = reg.Matches(LineText, ) For i As Integer = 0 To LineText.Length - 1 MsgBox(coll(i).Value) If (coll(i).Value = [String].Empty) Then cleanString = cleanString + " " Else cleanString = cleanString + coll(i).Value End If Next
the result was not pritty.... it removed spaces as well... how do i keep spaces and replace (NOT REMOVE) other characters with a space??? Thank you in advance."Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
Try using the Regex.Replace[^] function.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
hi all, How would one go about replacing a character in a string with a space where the character is not in the range of a-z or A-Z or 0-9 ??? the following Code did not have the planned outcome...
Dim cleanString As String = [String].Empty Dim reg As New Text.RegularExpressions.Regex("[A-Z]|[a-z]|[0-9]") Dim coll As Text.RegularExpressions.MatchCollection = reg.Matches(LineText, ) For i As Integer = 0 To LineText.Length - 1 MsgBox(coll(i).Value) If (coll(i).Value = [String].Empty) Then cleanString = cleanString + " " Else cleanString = cleanString + coll(i).Value End If Next
the result was not pritty.... it removed spaces as well... how do i keep spaces and replace (NOT REMOVE) other characters with a space??? Thank you in advance."Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison