Android Question Updating a list of 1D string arrays

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Experimenting with B4XTable and in that the data is set with a list of arrays.
Now in these arrays I have Excel dates and I need to alter these to tick dates and I do this with
this code fragment:

B4X:
            For c = 0 To arrDataTypes.Length - 1
                If arrDataTypes(c) = "XD" Then
                    For i = 0 To lstCSV.Size - 1
                        Dim arrRow() As String = lstCSV.Get(i)
                        arrRow(c) = cMP.ExcelDate2Ticks(arrRow(c))
                        lstCSV2.Add(arrRow)
                    Next
                End If
            Next

There is nothing wrong with this at all and it is quite fast and definitely fast enough, but I wonder if there would
be neater way to do this, avoiding the transfer to the second list, lstCSV2.

RBS
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Experimentation is good!
There is no need for a second list, you can change items in lists and arrays in situ.

B4X:
    Dim aList As List
    aList.Initialize
    aList.Add(Array As String("A", "B", "C"))
    
    Dim v() As String = aList.Get(0)
    v(1) = "X"
    
    Dim w() As String = aList.Get(0)
    Log(w(1))
    'X
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
That works fine indeed, thanks.
Not sure now why I thought there would be a problem doing it that simple way.

RBS
 
Upvote 0

emexes

Expert
Licensed User

Isn't it adding rows multiple times to lstCSV2?

To me it looks like if say 3 of the columns are of type "XD", then 3 times it is going to get all arrays from lstCSV, convert the relevant column, and add them to lstCSV2.

Or are lists smart enough to not add multiple/duplicate elements that refer to the same/one object/array?
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
You are right!
Not caused problems as there were never more than one XD column.

RBS
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
There is no need for a second list, you can change items in lists and arrays in situ.
Your example Willy is excellent. But, since the OP was dealing with dates, I thought to include this snippet corroborating your snippet
B4X:
Dim aList As List
    aList.Initialize
    aList.Add(Array ("A", "09/25/2023", "C"))   
    Dim v() As String = aList.Get(0)
    v(1) = DateTime.DateParse(v(1))
    For Each s() As String In aList        
        Log($"${s(0)}   ${s(1)}   ${s(2)} "$)    'logs:  A   1695614400000   C
    Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…