Remove all empty elements from string array

前端 未结 4 1149
误落风尘
误落风尘 2020-12-29 01:44

I have this:

List s = new List{\"\", \"a\", \"\", \"b\", \"\", \"c\"};

I want to remove all the empty elements

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 02:30

    Check out with List.RemoveAll with String.IsNullOrEmpty() method;

    Indicates whether the specified string is null or an Empty string.

    s.RemoveAll(str => string.IsNullOrEmpty(str));
    

    Here is a DEMO.

提交回复
热议问题