string Str = "      15年末        1063     ----";
 string Arry[];
 Arry[] =Str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
 TextBox1.Text=Arry[2].ToString();////////////////////////////////以上为代码/////////////////////////////////////
 
Arry[] 为三维数组:"15年末"
                   "1063"
                   "     ----"   //为啥这个前面的空格去不掉呢?
/////////////////////////////////以上为调试结果/////////////////////////////////
                   

解决方案 »

  1.   

    RemoveEmptyEntries 返回值不包括含有空字符串的数组元素  
      

  2.   

    你不用StringSplitOptions.RemoveEmptyEntries这个,前面的空格就去掉了
      

  3.   

    可能那些不是空格,这样试试:
    Arry[] =Str.Split(new char[]{' ', '\t', '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
      

  4.   

    StringSplitOptions.RemoveEmptyEntries 这个是将那些为空的串排除,不返回,和我要去除----前的空格没关系吧?wudliang 我试了,还是前面的str="    15年    1345    ----"
    第一个和第二个的空格都去掉了。不是空格会是什么啊?
      

  5.   

     TextBox1.Text = Arry[2].Trim().ToString();  
     如果说不是空格的话,那我用这个Trim()返回的东西就是正确的,去掉了前面的空白的。这是为什么?
      

  6.   

    string Str = " 15年末 1063     ----";
    Regex regex = new Regex(@"\s+");
    string str = regex.Replace(Str, "");
    用正则把,因为有些是制表符什么的
      

  7.   

    终极的解决办法是这样的:
    string Str = " 15年末 1063     ----";
                string[] Arry;
                Arry = Str.Split(new char[]{}, StringSplitOptions.RemoveEmptyEntries);
      

  8.   

    是否中文空格
    string Str = " 15年末 1063     ----";
    string[] arr=Str.Split(new string[]{" "}, StringSplitOptions.RemoveEmptyEntries);. 
      

  9.   

    //(1)
    string Str = " 15年末 1063     ----";
    Str=Str.remove(13)  //如果一个汉字算两个字符
    Arry[] =Str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
     TextBox1.Text=Arry[2].ToString();
    //--------------------------//(2)
    string Str = " 15年末 1063     ----";
    Str=Str.remove(11)  //如果一个汉字算一个字符
    Arry[] =Str.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
     TextBox1.Text=Arry[2].ToString();
    //-------------------------
    上面两种方法,仅供参考