使用C#从数组中删除空白值 [英] Remove blank values from array using C#
本文介绍了使用C#从数组中删除空白值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从数组中删除空白值?
How can I remove blank values from an array?
例如:
string[] test={"1","","2","","3"};
在这种情况下,是否有任何方法可以使用C#从数组中删除空白值?
in this case, is there any method available to remove blank values from the array using C#?
最后,我要获得以下格式的数组:
At the end, I want to get an array in this format:
test={"1","2","3"};
这意味着从数组中删除了2个值,最终我得到了3个.
which means 2 values removed from the array and eventually I get 3.
推荐答案
如果您使用的是.NET 3.5+,则可以使用LINQ(语言集成查询).
If you are using .NET 3.5+ you could use LINQ (Language INtegrated Query).
test = test.Where(x => !string.IsNullOrEmpty(x)).ToArray();
这篇关于使用C#从数组中删除空白值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文