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就是获取的每一行"="前所有的字符但是是错的,强高手给个答复,谢谢
{
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就是获取的每一行"="前所有的字符但是是错的,强高手给个答复,谢谢
解决方案 »
- XmlDocument 写入代码没有报错,但也没有写入,不知道那里错误
- 求一集装箱中最多可以放多少产品
- C# .NET显示状态转换问题?
- 纠结!!!为什么会变成这样呢??
- 命令参数遇到个小问题
- 如何用C#开发PDA蓝牙通信程序
- Excel讀進dataset 當Excel單元格裡字符超過大約255個時``後面的字符就丟失了``為什么??
- 求组
- 写程序时候,需要大量的有一定风格的ICON 按钮图标,国内几个素材网站没什么东西,有没有国外的素材网站,推荐几个! 谢谢。
- 请问如何动态添加hyerlink的点击事件???急!!!在线等。。。。
- Visual Studio 2005的MSDN为什么会这样子
- 如何实现软件界面?
StartIndex 不能小于 0。
参数名: startIndex
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(); 手写代码,大概应该是这样子根据自己的情况再修改下好了
{
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);
}
}
在我的机器上调试通过,试试看.
假如 strtext ="112323*1212=123123213123";
string[] str=new string[];
str=strtext.Split('=');
那么 str[0]="112323*1212";
str[1]="123123213123";
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);//最后在删掉第一行
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();