在C#中的数组摆脱空/空字符串值 [英] Getting rid of null/empty string values in a C# array
本文介绍了在C#中的数组摆脱空/空字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序,一个阵列使用string.Split获取数据(的char []分隔符)。
(使用';'作为分隔符)
I have a program where an array gets its data using string.Split(char[] delimiter). (using ';' as delimiter.)
某些值,虽然是空的。即该字符串有部分里没有数据,所以它是这样的:
Some of the values, though, are null. I.e. the string has parts where there is no data so it does something like this:
1; 2; ; 3;
1 ;2 ; ; 3;
这将导致null值我的数组。
This leads to my array having null values.
我该如何摆脱他们?
推荐答案
试试这个:
yourString.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries);
这篇关于在C#中的数组摆脱空/空字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文