逗号分隔的数组项列表
问题描述:
VB.NET 中是否有一个内置函数可以接受一个字符串数组并输出一串逗号分隔的项目?
Is there a built-in function in VB.NET which would take an array of strings and output a string of comma separated items?
示例:function( { "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):
调用语法:Dim sResults As String = MyCheckBoxList.ToStringList()
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