C#怎样去掉对于用Splict分隔的数组中的空值?

string[] arrayUserId = userIds.Split(new char[] { ',' },StringSplitOptions.RemoveEmptyEntries);

可以去掉比如:“12,3,,34,5,,,456,"中所含空值,最后会变成:“12,3,34,5,456"

如果userIds本身是空值那么使用Length就可以获取元素数为0

比如:userIds=“",那么使用上述代码可以得到:arrayUserId.Length==0,如果不使用上述代码而直接用userIds.Split(',')那么arrayUserId.Length==1这样就与实际不符了!

原文地址:https://www.cnblogs.com/firstcsharp/p/6203244.html