Avatar of Andy Green
Andy GreenFlag 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
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

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
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Andy Green
Andy Green
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

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.
Avatar of Andy Green
Andy Green
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks, works fine.

Andy
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo