Hello Everybody!
I need help with this task:
I have a flexgrid column filled with data that contains various chars but I want to eliminate all non-numerical and leave only the numbers.
Can anyone tell me how to write the code?
Thanks
Printable View
Hello Everybody!
I need help with this task:
I have a flexgrid column filled with data that contains various chars but I want to eliminate all non-numerical and leave only the numbers.
Can anyone tell me how to write the code?
Thanks
Are you talking about discrete numerals (like 1 or 4 or 8 etc) or are they actual numbers like 345 4.32 1,000.45 etc?
Actual numbers. Many of them are decimals
It will create another string with only numbers, commas and periods. If your string has at least one empty space between the numbers, you can also check if the current char is an empty space and add it to the new string too.Code:Dim myString As String = "aaa34BB12,000xcv9.9zz"
Dim ResultString As String
Dim i As Integer
For i = 0 To myString.Length - 1
If IsNumeric(myString.Chars(i)) = True OrElse myString.Chars(i) = "." OrElse myString.Chars(i) = "," Then
ResultString &= myString.Chars(i)
End If
Next
MessageBox.Show(ResultString)
Also, if the original string contains lots of numbers, it will be faster if you use StringBuilder instead of another string.
It works! Thanks a lot!