Comma “izing” a list of items

前端 未结 10 1688
我寻月下人不归
我寻月下人不归 2021-02-04 08:53

Given a list of strings, what is the best method for concatenating these strings into a comma separated list with no comma at the end. (VB.NET or C#) (Using either StringBuilder

10条回答
  •  不知归路
    2021-02-04 09:32

    Going on from the String.Join answer, to ignore null/empty strings (and if you are using .NET 3.5) you could use a bit of Linq. e.g.

    Dim Result As String
    Dim Items As New List(Of String)
    Items.Add("Hello")
    Items.Add("World")
    Result = String.Join(",", Items.ToArray().Where(Function(i) Not String.IsNullOrEmpty(i))
    MessageBox.Show(Result)
    

提交回复
热议问题