|
-
Nov 11th, 2006, 02:22 PM
#1
Thread Starter
Junior Member
[RESOLVED] Removing non numeric chars from a string
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
-
Nov 11th, 2006, 03:00 PM
#2
Re: Removing non numeric chars from a string
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?
-
Nov 11th, 2006, 03:14 PM
#3
Thread Starter
Junior Member
Re: Removing non numeric chars from a string
Actual numbers. Many of them are decimals
-
Nov 11th, 2006, 03:21 PM
#4
Re: Removing non numeric chars from a string
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)
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.
Also, if the original string contains lots of numbers, it will be faster if you use StringBuilder instead of another string.
-
Nov 11th, 2006, 03:24 PM
#5
Thread Starter
Junior Member
Re: Removing non numeric chars from a string
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|