Removing extra commas from string after using String.Join to convert array to string (C#)

前端 未结 9 642
花落未央
花落未央 2020-12-28 12:15

I\'m converting an array into a string using String.Join. A small issue I have is that, in the array some index positions will be blank. An example is below:

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 12:28

    Try this :):

    var res = string.Join(",", array.Where(s => !string.IsNullOrEmpty(s)));
    

    This will join only the strings which is not null or "".

提交回复
热议问题