How can I join an array of strings but first remove the elements of the array that are empty?

后端 未结 4 2086
孤独总比滥情好
孤独总比滥情好 2021-01-17 10:56

I am using the following:

return string.Join(\"\\n\", parts);

Parts has 7 entries but two of them are the empty string \"\". How can I fi

4条回答
  •  北海茫月
    2021-01-17 12:03

    You can use Where in LINQ to select strings which are not empty:

     return string.Join("\n", parts.Where(s => !string.IsNullOrEmpty(s)));
    

提交回复
热议问题