逗号分隔的数组项列表 [英] Comma Separated List of Array Items
本文介绍了逗号分隔的数组项列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
这篇关于逗号分隔的数组项列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文