Create comma separated list without last comma

I have a combobox with multiple selections and want to create a comma separated list form the selectedvalues.

I have this

Dim sbSp As New StringBuilder()
        Dim collectionSp As IList(Of RadComboBoxItem) = ddlUsers.CheckedItems
        For Each item As RadComboBoxItem In collectionSp
            sbSp.Append(item.Value + ",")
        Next

        RoomUsers = sbSp.ToString

What this gives me is the correct list but there is always a comma at the end.
What do I need to change to remove the comma.

Andy
LVL 3
Andy GreenAsked:
Who is Participating?
 
Kyle AbrahamsConnect With a Mentor Senior .Net DeveloperCommented:
Personally I would do this on the .Net  / ASP side:

RoomUsers = sbSp.ToString().Trim(",")
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
I've don this in SQL Server and Access VBA before, and essentially you get the length of the string, then all left characters of the length minus one.   Something like..

 RoomUsers = LEFT(sbSp.ToString, LEN(sbSp.ToString) - 1 )

Open in new window

0
 
Andy GreenAuthor Commented:
Thanks Guys, yes agree I want to do this before I send it off to the server, is there a test that can be done so its not added in the first place rather than add the comma them remove it?

Andy
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Test, well yes, but that would likely be much more code then just looping and adding the item.value + comma to a string, then after the loop slicing off the last comma at the end.
0
 
Andy GreenAuthor Commented:
Thanks, works fine.

Andy
0
All Courses

From novice to tech pro — start learning today.