卸下字符串数组所有空元素 [英] Remove all empty elements from string array
本文介绍了卸下字符串数组所有空元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的:
List<string> s = new List<string>{"", "a", "", "b", "", "c"};
我要删除所有空元素()
从它很快(可能通过LINQ),而不使用的foreach
语句,因为这使代码很难看。
I want to remove all the empty elements ("")
from it quickly (probably through LINQ) without using a foreach
statement because that makes the code look ugly.
推荐答案
您可以使用 列表。 removeall过
:
You can use List.RemoveAll
:
C#
s.RemoveAll(str => String.IsNullOrEmpty(str));
VB.NET
VB.NET
s.RemoveAll(Function(str) String.IsNullOrEmpty(str))
这篇关于卸下字符串数组所有空元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文