Hi,
I have a StatusStrip and is filled with Year in the format say "June2009 - May2010".
I want to get the years from this string like 2009,2010 from the above string.
Please suggest how can i do this.
I have tried this but not able to further separate June2009.
Please have a look

Dim strYearDet As String()
 strYear11, strYear2 As String
 strYearDet = StatusStrip1.Items(0).Text.Split("-")
 strYear11 = strYearDet(0)
 strYear2 = strYearDet(1)

Can anyone help of how to get 2009 and 2010 from the string

I would use the RegEx replace method to eliminate everything except digits.

Imports System.Text.RegularExpressions

Module Module1
   Sub Main()
      Dim s As String = "June2009 - May2010"
      Dim arr() As String = s.Split("-")

      Console.WriteLine(arr(0))
      Console.WriteLine(Regex.Replace(arr(0), "[^0-9]", ""))
      Console.WriteLine(Regex.Replace(arr(1), "[^0-9]", ""))
   End Sub

End Module
Private Function ExtractNumbers(ByVal expr As String) As String
        Return String.Join(Nothing, System.Text.RegularExpressions.Regex.Split(expr, "[^\d]"))
    End Function

write this function in ur form and call this it will return only number in string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.