Solved

Create comma separated list without last comma

Posted on 2014-11-14
5
82 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
  • 2
  • 2
5 Comments
 
LVL 65

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 39

Accepted Solution

by:
Kyle Abrahams earned 500 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 65

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query Missing Money orders... 6 72
Ranking Based On Value 3 29
SQL Inner Join Vs SubQueries 9 26
add 1 to a field for 100 rows 11 24
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now