c# - 你会如何从数组中删除空白条目

标签 c#

如何从数组中删除空白项?

迭代并将非空白项分配给新数组?

String test = "John, Jane";

//Without using the test.Replace(" ", "");

String[] toList = test.Split(',', ' ', ';');

最佳答案

使用带有 StringSplitOptionsstring.Split 的重载:

String[] toList = test.Split(new []{',', ' ', ';'}, StringSplitOptions.RemoveEmptyEntries);

关于c# - 你会如何从数组中删除空白条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4798755/

相关文章:

c# - 如何使用另一个程序集的内部类

c# - 检查数字的小数点和总长度

c# - 将 LINQ 表达式传递给另一个 QueryProvider

c# - String.Concat(String, String, String, String) 有什么意义

c# - 表单和代码不同步

c# - 强制选项卡到扩展的 .net 控件中的下一个控件

c# - 如何使 SelectList 中的 selectedItem 成为动态的

c# - 如何评估包含局部变量名称的字符串作为 C# 中的代码

c# - 如何调用返回引用游标的Oracle存储过程

c# - 如何在 C++ CLR 中将 byte[] 返回给 C#