Avatar of Andy Green
Andy Green
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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
Microsoft SQL Server

Avatar of undefined
Last Comment
Andy Green

8/22/2022 - Mon
Jim Horn

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

ASKER CERTIFIED SOLUTION
Kyle Abrahams

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Andy Green

ASKER
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
Jim Horn

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Andy Green

ASKER
Thanks, works fine.

Andy