Android Question Date Parser

Sergey_New

Well-Known Member
Licensed User
Longtime User
Date can be represented as shown in the code.
Need to get the year value from these date representations.
I did it like this:
B4X:
Sub Globals
    Dim Label1 As Label
    Dim Spinner1 As Spinner
    Dim patYear As String = "(?:(?:\w{0,4})\s?(?:\d{0,3})\s?(?:\D{3})\s?)?(\d{1,4})\s?"
End Sub

Sub Activity_Create(firstTime As Boolean)
    Activity.LoadLayout("main")
    Spinner1.Add("2000")
    Spinner1.Add("CAL 2001")
    Spinner1.Add("FROM 2002 TO 2003")
    Spinner1.Add("30 May 2003")
    Spinner1.Add("CAL 30 May 2004")
    Spinner1.Add("FROM 30 May 2005 TO 30 Iun 2006")
End Sub

Private Sub Spinner1_ItemClick (Position As Int, Value As Object)
    Label1.Text=""
    Dim m As Matcher = Regex.Matcher(patYear,Value)
    Do While m.Find
        If m.Group(1)<> m.Group(0) Then
            Label1.Text="~" & m.Group(1)
        Else
            Label1.Text=m.Group(1)
        End If
        Exit
    Loop
End Sub
I would like to have more options.
Please help me change the pattern to get 4 groups: first date prefix, first date, second date prefix, second date.
 

Attachments

  • test.zip
    3.3 KB · Views: 80
Top