[Gambas-user] convert string to collection

Mayost Sharon sharon at 455.co.il
Wed May 3 21:11:19 CEST 2023



בס"ד

שלום וברכה,


בברכה
מיוסט שרון

נייד: 058-4002542
נייח משרד: 02-5498005
נייח בית: 02-5498008

---------- Original Message -----------
From: T Lee Davidson <t.lee.davidson at gmail.com>
To: user at lists.gambas-basic.org
Sent: Wed, 3 May 2023 13:49:00 -0400
Subject: Re: [Gambas-user] convert string to collection

> On 5/3/23 12:05, Mayost Sharon wrote:
> > I want to convert the string to a collection
> > 
> > The way I did it is:
> > 
> > Public Sub Main()
> >    Dim col_01 As New Collection
> >    Dim ar_s_01 As String[]
> >    Dim s_01 As String
> >    Dim s_02 As String
> >    
> >    s_01 = "Event: Hangup\nPrivilege: call, all\nChannel: SIP / 4 F2060EB4 - 00000000\nUniqueid: 1283174108.0\nCallerIDNum: 2565551212\nCallerIDName: Russell Bryant\nCause: 16\nCause - txt: Normal Clearing"
> >    
> >    ar_s_01 = Split(s_01, Chr(10))
> >    
> >    For Each s_02 In ar_s_01
> >      col_01.Add(Trim(Split(s_02, ":")[1]), Trim(Split(s_02, ":")[0]))
> >    Next
> >    
> >    Print col_01["Event"]
> >    Print col_01["Privilege"]
> >    Print col_01["Uniqueid"]
> >    Stop
> > End
> > 
> > Is this the right way?
> > Or is there a shorter way to do it?
> > 
> > Thank you
> That looks about right. The only thing I can think of to make it shorter, but 
> not by much, is to replace:   ar_s_01 = Split(s_01, Chr(10))
> 
>    For Each s_02 In ar_s_01
>      col_01.Add(Trim(Split(s_02, ":")[1]), Trim(Split(s_02, ":")[0]))
>    Next
> 
> with:
>    For Each s_02 In Split(s_01, Chr(10))
>      col_01.Add(Trim(Split(s_02, ":")[1]), Trim(Split(s_02, ":")[0]))
>    Next
> 
> -- 
> Lee
> 
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
------- End of Original Message -------

Thanks


More information about the User mailing list