A apty Active Member Licensed User Longtime User May 25, 2018 #1 i have a list that looks like below: Code: Copy abcd efgh ijkl I want to merge this list and have a single string joined with comma like below: Code: Copy abcd,efgh,ijkl Please assist.
i have a list that looks like below: Code: Copy abcd efgh ijkl I want to merge this list and have a single string joined with comma like below: Code: Copy abcd,efgh,ijkl Please assist.
M Mahares Expert Licensed User Longtime User May 25, 2018 #2 apty said: I want to merge this list and have a single string joined with comma like below: Click to expand... Maybe something simple like this: Code: Copy Dim MyList As List MyList.Initialize MyList.Add("abcd") MyList.Add("efgh") MyList.Add("ijkl") Dim str As String For i=0 To MyList.Size-1 str=str & MyList.Get(i) & "," Next str=str.SubString2(0,str.Length-1) Log(str) 'displays: abcd,efgh,ijkl Upvote 0
apty said: I want to merge this list and have a single string joined with comma like below: Click to expand... Maybe something simple like this: Code: Copy Dim MyList As List MyList.Initialize MyList.Add("abcd") MyList.Add("efgh") MyList.Add("ijkl") Dim str As String For i=0 To MyList.Size-1 str=str & MyList.Get(i) & "," Next str=str.SubString2(0,str.Length-1) Log(str) 'displays: abcd,efgh,ijkl
Erel B4X founder Staff member Licensed User Longtime User May 25, 2018 #3 I recommend you to watch the strings tutorial: https://www.b4x.com/etp.html Code: Copy Sub ListToString(list As List) As String If list.Size = 0 Then Return "" Dim sb As StringBuilder sb.Initialize For Each s As String in list sb.Append(s).Append(",") Next sb.Remove(sb.Length - 1, sb.Length) Return sb.ToString End Sub Code will work the same in B4A, B4i and B4J. Upvote 0
I recommend you to watch the strings tutorial: https://www.b4x.com/etp.html Code: Copy Sub ListToString(list As List) As String If list.Size = 0 Then Return "" Dim sb As StringBuilder sb.Initialize For Each s As String in list sb.Append(s).Append(",") Next sb.Remove(sb.Length - 1, sb.Length) Return sb.ToString End Sub Code will work the same in B4A, B4i and B4J.