zoukankan      html  css  js  c++  java
  • 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这样就与实际不符了!

  • 相关阅读:
    例7-13
    例7-11
    例7-1
    例6-5
    例6-3
    例6-2
    例6-1
    例5-9
    例5-8
    例5-7
  • 原文地址:https://www.cnblogs.com/firstcsharp/p/6203244.html
Copyright © 2011-2022 走看看