Is there a built-in function in VB.NET which would take an array of strings and output a string of comma separated items?
E开发者_运维技巧xample: function( { "Sam","Jane","Bobby"} ) --> "Sam, Jane, Bobby"
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
Use string.Join
:
string commaSep = string.Join(",", myArray);
Use
String.Join(",", arrayWithValues)
See here
String.Join Method (String, array[])
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.
精彩评论