Solved

Create comma separated list without last comma

Posted on 2014-11-14
5
85 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 40

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

867 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