tags:

views:

93

answers:

5

Is there a built-in function in VB.NET which would take an array of strings and output a string of comma separated items?

Example: function( { "Sam","Jane","Bobby"} ) --> "Sam, Jane, Bobby"

A: 

I don't know about VB, but C# has a String.Join method which can concatanate a string array delimited by a nominated character. Presume VB is almost identical.

Program.X
The `String` class is part of the base class library and therefore available to all .NET languages.
Oded
+2  A: 

String.Join Method (String, array[])

CSharpAtl
+4  A: 
String.Join(",", YourArray) 

Additionally, if you want to get all selected items from a checkboxlist (or radiobuttonlist) you could use an extension method (checkboxlist shown below):

Call Syntax: Dim sResults As String = MyCheckBoxList.ToStringList()

    <Extension()> _
    Public Function ToStringList(ByVal cbl As System.Web.UI.WebControls.CheckBoxList) As String
        Dim separator As String = ","
        Dim values As New ArrayList
        For Each objItem As UI.WebControls.ListItem In cbl.Items
            If objItem.Selected Then
                values.Add(objItem.Value.ToString)
            End If
        Next
        Return String.Join(separator, values.ToArray(GetType(String)))
    End Function
Kyle B.
+3  A: 

Use

String.Join(",", arrayWithValues)

See here

froadie
+3  A: 

Use string.Join:

string commaSep = string.Join(",", myArray);
Oded