StreamReader sr2 = new StreamReader(path);//path是我定一定的一个文本路径
            
            {
                string strtext;
                {
                    while ((strtext = sr2.ReadLine()) != null)
                    {
                       
                        comboBox1.Items.Add(strtext);
                    }
                }
            }
            sr2.Close();如果是这样的话,是获取文本中所有行,并且把每一行写入到combobox的项中。1,我现在要获取从第而行开始,获取字符“=”号前所有的字符
2,获取“=”号后所有的字符
3,不把文本的第一行写入到combobox中。
下面是我的一个错误写法,请大家指出
 string str = strtext.Substring(0,Strtext.lastIndexof("="));
 str就是获取的每一行"="前所有的字符但是是错的,强高手给个答复,谢谢

解决方案 »

  1.   

    string str = strtext.Substring(Strtext.lastIndexof("=")); 
      

  2.   

    你可以读一行,但只向combox中加入=前的字符啊
      

  3.   

    一楼的回复不行啊出错:
    StartIndex 不能小于 0。
    参数名: startIndex
      

  4.   

    strtext.Substring(Strtext.lastIndexof("=")); 
      

  5.   

    1,2 : 用string.Split('='); //以=号进行数据截取将截取后的数据存入数组,灵活调用3 : 循环前readline一下,就到第二行了
      

  6.   

    StreamReader sr2 = new StreamReader(path);//path是我定一定的一个文本路径
    sr2.ReadLine(); //3.不把文本的第一行写入到combobox中。string[] results;
    while (sr2.Peek()>=0)

      results=sr2.ReadLine().Split('=');//results[0]是=前的字符串,results[1]是=后的字符串
      comboBox1.Items.Add(results[0]);
    }sr2.Close(); 手写代码,大概应该是这样子根据自己的情况再修改下好了
      

  7.   

            private void Form1_Load(object sender, EventArgs e)
            {
                StreamReader sr = new StreamReader(@"D:\DotNet2005\test.txt");
                string strText, leftText, rightText;
                while ((strText=sr.ReadLine()) != null)
                {
                    leftText = strText.Substring(0,strText.IndexOf('='));
                    rightText = strText.Substring(strText.IndexOf('=') + 1);
                    comboBox1.Items.Add(leftText);
                    comboBox1.Items.Add(rightText);
                }
            }
         在我的机器上调试通过,试试看.
      

  8.   

    你要详细点啊:补充6楼的
    假如 strtext ="112323*1212=123123213123";
    string[] str=new string[];
    str=strtext.Split('=');
    那么 str[0]="112323*1212";
        str[1]="123123213123";
     
      

  9.   


              StreamReader sr2 = new StreamReader(path);//path是我定一定的一个文本路径 
                 
                { 
                    string strtext; 
                    { 
                        while ((strtext = sr2.ReadLine()) != null) 
                        { 
                            
                            comboBox1.Items.Add(strtext.Split('=')[0].Trim()); 
                        } 
                    } 
                } 
                sr2.Close();           comboBox1.Items.RemoveAt(0);//最后在删掉第一行
      

  10.   


     StreamReader sr2 = new StreamReader(path);//path是我定一定的一个文本路径 
            {
                string strtext;
                sr2.ReadLine();//读取第一行
                while ((strtext = sr2.ReadLine()) != null)
                {
                    string[] s1 = strtext.Split('=');//分割字符串
                    comboBox1.Items.Add(s1[0].Trim());//添加
                }
            }
            sr2.Close();