?
Solved

Create comma separated list without last comma

Posted on 2014-11-14
5
Medium Priority
?
90 Views
Last Modified: 2014-11-17
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
0
Comment
Question by:Andy Green
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40443020
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
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 40443038
Personally I would do this on the .Net  / ASP side:

RoomUsers = sbSp.ToString().Trim(",")
0
 
LVL 3

Author Comment

by:Andy Green
ID: 40443065
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
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40443079
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
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 40446751
Thanks, works fine.

Andy
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question