Imports System.Text.RegularExpressions
Public Class Tester
Public Shared Sub Main
Dim source As String = _
"This 321.0 string -0.020 contains " & _
"3.0E-17 several 1 2. 34 numbers"
Dim parser As New _
Regex("[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?")
Dim sourceMatches As MatchCollection = parser.Matches(source)
Dim counter As Integer
Console.WriteLine(sourceMatches.Count.ToString() & vbNewLine)
For counter = 0 To sourceMatches.Count - 1
Console.WriteLine(sourceMatches(counter).Value.ToString())
Console.WriteLine(CDbl(sourceMatches(counter).Value).ToString())
Next counter
End Sub
End Class
|