假如我有一个字符串是“|abc||efg||hig||klm|”
现在我想分别取出每两个“|“之间的字符串,例如上面的字符串我想分别取出abc, efg, hig, klm
如何能办的到呢?望各位能解答小弟的问题。

解决方案 »

  1.   

    1. 字符串替换, 把每两个 || 替换成一个字符串中没有的字符, 比如 $ .
    2. 按 $ 执行 split 方法.
      

  2.   

    string str = "|abc||efg||hig||klm|"
    str = str.Replace("||","^");
    string str[] = str.Split('^');
    ...
      

  3.   

    string strForSplilt = "|abc||efg||hig||klm|" ;
                string[] splitStrArr = strForSplilt.Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries);
      

  4.   

    定义数组 arry 
    string str = "|abc||efg||hig||klm|" 
    string test =str.Replace("||",","); 
    arry = test.split(',')
    for(int i =0; i<=arry.length; i++)
    {
        string resul = resul + arry[i];
    }
      

  5.   


    string s = "|abc||efg||hig||klm|";
            s = s.TrimStart('|').TrimEnd('|');
            s = s.Replace("||", "|");
            string[] strs = s.Split('|');
            foreach (string str in strs)
            {
     
            }
      

  6.   


    为什么要加 s= s.TrimStart('|').TrimEnd('|');?
    不能s.Split("||");?
      

  7.   

    粘错了 s= s.Replace("||","|");
      

  8.   

    str.Split('|', StringSplitOptions.RemoveEmptyEntries);