vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Tuesday, February 14, 2012

Split the fractional number in a string using regular expression


Introduction:

In this article you're going to see about split fractional number in a string variable.
Description:
If you need search or split only fractional number in a string then you can use following regular expression method.

By using regex you can find anything you want...but only thing you need to know how to use and write the regex expression.
Some useful characters used in Regex expression:
[ ]  Used to match anything inside the square brackets for example [0-9] it match any character between 0 to 9

Code:
Dim str As String = "abcdefgh99.99ghtiojkj45678thyo899.00"

        Dim t1 As New List(Of String)
        Dim t As MatchCollection
        t = Regex.Matches(str, "[-+]?[0-9]*\.?[0-9]+")

        For Each itm As Match In t
            t1.Add(itm.Value)
        Next

Finally t1 has contains only the value 99.99,4567 and 899.00

I hope you enjoy this code……..

0 comments:

Post a Comment