listbox to concatenated string
I have a listbox with Multiple selection. Probably a simple question but how can I assign the Items in the list to a single concatenated (comma separated) string?
-
You need to cast the variable from your output in your form where the multi-selection takes place to an IList<Object> variable.
Then, Assign a str variable (x ) to an empty str= ""
Then, do a For Each <Object> and use the cast variable mentioned above.
Put an Assign activity in the body of the For Each where the string variable x = item + "," + x
You'll end up with a list that ends in ",", which you can just take out determining the length of x. Ex: finalString = Left(x,Len(x)-1)
0 -
Thanks for your help Ryan.
I am getting an error on the Assign activity x = item + "," + x
Option Strict On prohibits operands of type Object for operator '+'
0 -
Looks like I just needed to add.
x = item.toString + "," + x
Thanks again.
0 -
fyi,
it will be much safter and faster (?) with
x = string.format("{0}, {1}", item, x)
0 -
Import System.Linq and use the following to create a valid where clause:string.Format("columname IN ({0})",String.Join(",", CType(listvar, IList(Of Object)).Select(Function(value) "'" & value.ToString & "'")))
Change columnname to the column name in your data.
listvar is the object returned from the listbox.0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
5 Kommentare