摆脱 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.)
不过,有些值是空的.IE.字符串有没有数据的部分,所以它会做这样的事情:
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;
这导致我的数组具有空值.
This leads to my array having null values.
我该如何摆脱它们?
推荐答案
试试这个:
yourString.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries);
这篇关于摆脱 C# 数组中的空/空字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文