B4J Question How to split a table

Brian Michael

Active Member
Licensed User
Hi

Im trying to split a plain table like this:

# NAME AGE
1 BRIAN 23
2 MARK 10

With this code:

B4X:
Lines = Regex.Split(CRLF,TextArea1.text)
    Dim columns() As String

        If(Msg.Show2("¿Have column?","Aviso","Yes","No","")) = -1 Then
               
            columns=Regex.Split(" ",Lines(0).Replace("  "," "))
               
            For i = 0 To c.Length
                lstColumns.Add(columns(i))
            Next
               
            For i = 0 To Lines.Length
                lstFiles.Add(Lines(i))
            Next
        End If

    Log(lstColumns)

For store the columns and rows in a list but its does'nt work,s can anyone help me with this idea?
 
Last edited:
Solution
Never use modal dialogs. You should use Msgbox2Async instead.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim s As String = $"#   NAME       AGE
1   BRIAN   23
2   MARK    10 "$
    Dim Rows As List
    Rows.Initialize
    Dim Headers As List
    Headers.Initialize
    
    Msgbox2Async("Add headers?", "", "Yes", "", "No", Null, False)
    Wait For Msgbox_Result (Result As Int)
    Dim AddHeaders As Boolean = (Result = DialogResponse.POSITIVE)
    For Each line As String In Regex.Split(CRLF, s)
        Dim Items() As String = Regex.Split("\s+", line)
        If AddHeaders And Headers.Size = 0 Then
            Headers.AddAll(Items)
        Else
            Rows.Add(Items)
        End If
    Next
    Log(Headers)
    For Each row()...

Erel

B4X founder
Staff member
Licensed User
Longtime User
Never use modal dialogs. You should use Msgbox2Async instead.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim s As String = $"#   NAME       AGE
1   BRIAN   23
2   MARK    10 "$
    Dim Rows As List
    Rows.Initialize
    Dim Headers As List
    Headers.Initialize
    
    Msgbox2Async("Add headers?", "", "Yes", "", "No", Null, False)
    Wait For Msgbox_Result (Result As Int)
    Dim AddHeaders As Boolean = (Result = DialogResponse.POSITIVE)
    For Each line As String In Regex.Split(CRLF, s)
        Dim Items() As String = Regex.Split("\s+", line)
        If AddHeaders And Headers.Size = 0 Then
            Headers.AddAll(Items)
        Else
            Rows.Add(Items)
        End If
    Next
    Log(Headers)
    For Each row() As String In Rows
        Dim lrow As List = row 'just to have nicer logs
        Log(lrow)
    Next
End Sub
 
Upvote 0
Solution
Top