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

Discussion in 'Android Questions' started by petr4ppc, Mar 7, 2015.

  1. petr4ppc

    petr4ppc Active Member Licensed User

    Dear friends, please for help,

    I have

    this STRING :
    Code:
    (ArrayList) [DisplayName=John, Starred=falseId=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
     
  2. KZero

    KZero Active Member Licensed User

    you mean String Array ?

    try
    Code:
    '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: Mar 7, 2015
  3. petr4ppc

    petr4ppc Active Member Licensed User

    Dear K zero,

    I have

    Code:
    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
     
  4. klaus

    klaus Expert Licensed User

    You need to give more information !
    Where does the string come from ?
    How was it defined ?
    etc.
     
    NJDude likes this.
  5. petr4ppc

    petr4ppc Active Member Licensed User

    Klaus,

    thank you for your answer


    Code:
    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
     
  6. KZero

    KZero Active Member Licensed User

    FindByName returns List not String

    try this code instead
    Code:
    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
     
  7. petr4ppc

    petr4ppc Active Member Licensed 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


     
  8. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    try the code below:
    Code:
    '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"))
     
    spairo and KZero like this.
  9. KZero

    KZero Active Member Licensed User

    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

    Code:
    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
     
  10. petr4ppc

    petr4ppc Active Member Licensed 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
     
    KZero likes this.
  11. Troberg

    Troberg Well-Known Member Licensed 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.
     
    KZero likes this.
  12. petr4ppc

    petr4ppc Active Member Licensed 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice