Please help me convert the C# code to VB.Net
-
Hi, I beleive this sample code is in C#:
string cleanString = String.Empty; Regex reg = new Regex("[A-Z]|[a-z]"); MatchCollection coll = reg.Matches(<MyStringGoesHere>); for(int i = 0; i < coll.Count; i++) { cleanString = cleanString + coll[i].Value; }
See, i want to remove all characters that do not fall in the A-Z or a-z OR 0-9 category AND replace it with a space... example test123t3er = test t er Am i wrong in saying that theRegex reg = Regex("[A-Z]|[a-z]")
CAN IT BE:Regex reg = Regex("[A-Z]|[a-z]|[0-9]")
??? AND thecleanString = cleanString + coll[i].Value;
CAN I DO A TEST:IF(coll[i].Value == String.Empty)
THENcleanString = cleanString + " "
; ELSEcleanString = cleanString + coll[i].Value
???? - in this way i add space if the character is not in the above category???? So please help me convert the very top section of code and i will build from there... 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, I beleive this sample code is in C#:
string cleanString = String.Empty; Regex reg = new Regex("[A-Z]|[a-z]"); MatchCollection coll = reg.Matches(<MyStringGoesHere>); for(int i = 0; i < coll.Count; i++) { cleanString = cleanString + coll[i].Value; }
See, i want to remove all characters that do not fall in the A-Z or a-z OR 0-9 category AND replace it with a space... example test123t3er = test t er Am i wrong in saying that theRegex reg = Regex("[A-Z]|[a-z]")
CAN IT BE:Regex reg = Regex("[A-Z]|[a-z]|[0-9]")
??? AND thecleanString = cleanString + coll[i].Value;
CAN I DO A TEST:IF(coll[i].Value == String.Empty)
THENcleanString = cleanString + " "
; ELSEcleanString = cleanString + coll[i].Value
???? - in this way i add space if the character is not in the above category???? So please help me convert the very top section of code and i will build from there... 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
I believe this is the VB.Net code
Dim cleanString As String = [String].Empty Dim reg As New Regex("[A-Z]|[a-z]") Dim coll As MatchCollection = reg.Matches(<MyStringGoesHere> ) For i As Integer = 0 To coll.Count - 1 cleanString = cleanString + coll(i).Value Next
-
I believe this is the VB.Net code
Dim cleanString As String = [String].Empty Dim reg As New Regex("[A-Z]|[a-z]") Dim coll As MatchCollection = reg.Matches(<MyStringGoesHere> ) For i As Integer = 0 To coll.Count - 1 cleanString = cleanString + coll(i).Value Next
wow, thanks... that was super fast.... :-D
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
-
wow, thanks... that was super fast.... :-D
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
Your welcome ;)
-
Hi, I beleive this sample code is in C#:
string cleanString = String.Empty; Regex reg = new Regex("[A-Z]|[a-z]"); MatchCollection coll = reg.Matches(<MyStringGoesHere>); for(int i = 0; i < coll.Count; i++) { cleanString = cleanString + coll[i].Value; }
See, i want to remove all characters that do not fall in the A-Z or a-z OR 0-9 category AND replace it with a space... example test123t3er = test t er Am i wrong in saying that theRegex reg = Regex("[A-Z]|[a-z]")
CAN IT BE:Regex reg = Regex("[A-Z]|[a-z]|[0-9]")
??? AND thecleanString = cleanString + coll[i].Value;
CAN I DO A TEST:IF(coll[i].Value == String.Empty)
THENcleanString = cleanString + " "
; ELSEcleanString = cleanString + coll[i].Value
???? - in this way i add space if the character is not in the above category???? So please help me convert the very top section of code and i will build from there... 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
You could easily do this in a RegEx by itself and avoid looping through the matches. \W captures all non-word characters (anything not a-z A-Z or 0-9), so you can then just use the Replace method of the Regex class.
Dim resultString As String
resultString = System.Text.RegularExpressions.Regex.Replace("ABC$%123*>890!#XYZ", "\W", " ")I haven't done VB since VB6, but I assume that should work as it's a simple statement.