从数组 vb.net 中删除空字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26804676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
remove empty string from array vb.net
提问by Dman
I am trying to get each sentence from my rtextboxinto an array. However, when I use .splitmethod, it gives me empty spaces as part of the array.
我试图将我的每个句子rtextbox放入一个数组中。但是,当我使用.split方法时,它给了我空格作为数组的一部分。
How can I either remove the empty ones or not have them come into the array in the first place?
我怎样才能删除空的或不让它们首先进入数组?
Dim senArray() = RTextBox.Text.Split(New String() {"."}, StringSplitOptions.RemoveEmptyEntries)
Thank you!
谢谢!
回答by James Thorpe
You can use a linq Whereexpression to remove the whitespace entries:
您可以使用linqWhere表达式来删除空格条目:
Dim senArray() = RTextBox.Text.Split(
New String() {"."}, StringSplitOptions.RemoveEmptyEntries
).Where(
Function(s) Not String.IsNullOrWhitespace(s)
).ToArray()

