string[]   arr   =   guestneeds.Split('\n'); 
   foreach (string s in arr)
            {
                int leng1 = s.Length;
                int leng2 = s.IndexOf(',');
                needtxt = needtxt +  s.Substring(leng2 + 1,leng1-2)
            }
总是报错,看不出哪有问题啊??请指教了报错内容:
索引和长度必须引用该字符串内的位置。
参数名: length

解决方案 »

  1.   

    可能 leng1  小於 leng2,或者 leng1<=2
      

  2.   

    字符串问题string   a="aggagahh";  
      Response.Write(a.Substring(1,2));  
       
      返回-------gg注意:第二个参数是取几位,
      

  3.   

    public string Substring (
    int startIndex,
    int length
    )子字符串从指定的字符位置开始且具有指定的长度你用leng1-2肯定是出错啦
      

  4.   

    这样的还是用这个
    string strYour = "test,test,s,a,b,d,e,f";
    string[] subItems = strYour.Split(",");
      

  5.   

    嗯,找到原因了,就是因为Substring的第二个参数太长了,不应是leng1-2而应是leng1 - leng2 - 2。