Android Question I have String = Array List - 5 Values ... I need get one of them

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please for help,

I have

this STRING :
B4X:
(ArrayList) [DisplayName=John, Starred=false, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John]

How can I get please very much the value TimesContacted and the value Name from the STRING?
Thank you very much
p4ppc
 

KZero

Active Member
Licensed User
Longtime User
you mean String Array ?

try
B4X:
'Put the variable name instead of S
S(0) 'Display name 
S(1) 'Starred
S(2) 'Id
S(3) 'Notes
S(4) 'TimesContacted
.......
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
you mean String Array ?

try
B4X:
'Put the variable name instead of S
S(0) 'Display name
S(1) 'Starred
S(2) 'Id
S(3) 'Notes
S(4) 'TimesContacted
.......
Dear K zero,

I have

B4X:
Dim mystring as String
Log(mystring)

And in log message I get this: (ArrayList) [DisplayName=John, Starred=false, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John]

I want get the values from this string.....
Thank you very much
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Klaus,

thank you for your answer


B4X:
Dim findincotacts As Contacts2
Dim Mystring As String
Mystring=findincotacts.FindByName("John",False,True,False)
Log(Mystring)


And in log message I get this:
(ArrayList) [DisplayName=John, Starred=false, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John]

How can I get value from this string. For example Id?
Thank you very much

p4ppc
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
FindByName returns List not String

try this code instead
B4X:
Dim findincotacts As Contacts2
Dim aList As List
aList.Initialize
aList=findincotacts.FindByName("John",False,True,False)
For i = 0 To aList.Size -1
    Log(aList.Get(i))
Next
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
KZero,

thank you for your answer.
I tryed your code, but lin Log message I get this result:
DisplayName=John, Starred=false, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John

but how can I get only value which I need, for example Id?
Dim readid as String
readid=value ID from aList

I am trying .Get(i) and .IndexOf(i) but nothing...

Please for help,
thank you very much

p4ppc


 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

try the code below:
B4X:
'Create a list which holds the requested arraylist. The arraylist is a map
Dim l As List : l.Initialize
'(ArrayList) [DisplayName=John, Starred=False, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John]
'Create the arraylist and add to the list
l.Add(CreateMap("DisplayName":"John", "Starred":False, "Id":5, "Notes":"", "TimesContacted":110, "LastTimeContacted":"1425121693778", "Name":"John"))
'Log the list which shows the same content as requested (ArrayList)...
Log(l)
'Example to Log all map entries Key and Value by getting the first entry of the list which is the map
Dim m As Map = l.Get(0)
For i = 0 To m.Size - 1
    Log(m.GetKeyAt(i) & " = " & m.GetValueAt(0))
Next
'
'Now get any key requested, like
'
'Get Name - which outputs John
Log("Name is " & m.Get("Name"))
'Get TimesContacted - which outputs 110
Log("TimesContacted is " & m.Get("TimesContacted"))
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
KZero,

thank you for your answer.
I tryed your code, but lin Log message I get this result:
DisplayName=John, Starred=false, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John

but how can I get only value which I need, for example Id?
Dim readid as String
readid=value ID from aList

I am trying .Get(i) and .IndexOf(i) but nothing...

Please for help,
thank you very much

p4ppc


FindByName returns all matched contacts not always 1 contact
each item contains all the contact's data
the easiest way to split this data to use Regex

B4X:
Dim findincotacts As Contacts2
Dim aList As List
Dim ContactData() As String
aList=findincotacts.FindByName("John",False,True,False)
For i = 0 To aList.Size -1
    ContactData = Regex.Split(",",aList.Get(i))
    For j = 0 To ContactData.Length -1
        Log(ContactData(j))
    Next
Next
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,
thank you very much for your ideas.....

RWBLINN:
IFrom string I get this:
(ArrayList) [DisplayName=John, Starred=False, Id=5, Notes=, TimesContacted=110, LastTimeContacted=1425121693778, Name=John]
and you wrote, that I must define - create this :
listl.Add(CreateMap("DisplayName":"John", "Starred":False, "Id":5, "Notes":"", "TimesContacted":110, "LastTimeContacted":"1425121693778
I must do it handly? Excuse me, now I not undesrstand what I must to do....
But thank you very much for your answer an help.

KZero
I have tryed your code. I get string which I need. It is simple and OK, thank you very much for your help!!

Best regards
p4ppc
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
Just use the code Kzero gave you, then cut up the string at ",", remove leading spaces from the string pieces, cut each pieace at "=" and then you have the key and value.

Just look at the string handling functions, they have all the tools you need.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Troberg -

thank you very much for your help, now I understand RWBLINN advice.
Thank you very much RWBLINN!!

Classic string handling functions + RWBLINN advice

Thank you very much
Best regards

p4ppc
 
Upvote 0
Top