I wrote the code for only extracting the numbers.
Public Class Number
Public Value As Integer, Position As Integer
Public Sub New(v As Integer, p As Integer)
Value = v
Position = p
End Sub
End Class
Public Shared Function ExtractNumbers(str As String) As List(Of Number)
Dim r As New List(Of Number)()
Dim l As Integer = str.Length
Dim i As Integer = 0
Dim tmp As String = ""
Dim t As Integer
For i = 0 To l - 1
If Char.IsDigit(str(i)) Then
t = i
tmp = ""
tmp = tmp & str(i)
i += 1
While Char.IsDigit(str(i))
tmp = tmp & str(i)
i += 1
End While
r.Add(New Number(Integer.Parse(tmp), t))
End If
Next
Return r
End Function
I wrote this code myself. The function
ExtractNumbers
returns a list of Number. The Number class has two variables
Value
and
Position
.
Value
is the value of the number.
Position
is the position of the number in the list. Use it like this:
Dim a As String = "ON 25/03/2014 u need to pay Rs 2000."
Dim ln As List(Of Number) = ExtractNumbers(a)