int index1 = 0;
                int index2 = 0;
                for (int x = 0; x < 3; x++)
                {
                    index1 = temptext.IndexOf("\r\n", index2,temptext.Length - index2 - 1);
                    index2 = index1;
                }以上代码,老是取到第一行的索引,请问,如何取到第三行的索引?

解决方案 »

  1.   

    index2<temptext.Length-1?index2+1:temptext.Length-1;
    index1 = temptext.IndexOf("\r\n", index2,temptext.Length - index2 - 1);
    index2 = index1;
      

  2.   

    int index1 = 0;
    int index2 = 0;
    for (int x = 0; x < 3; x++)
    {
    index1 = temptext.IndexOf("\r\n", index2,temptext.Length - index2 - 1);
    index2 = index1+1;
    }index2要增加1另外如果是            
    string[] str = temptext.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);你要的第3行数据就是 str 数组的第二个元素
      

  3.   

    string[] arr=File.ReadAllLine();
    foreach(string s in arr)
    {
    atring[] arr2=s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);}