ListBox 导入 TXT 文本 本帖最后由 prestashop 于 2011-06-25 10:25:29 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看了你的代码,感觉貌似在while循环中缺少点什么:你的while循环感觉只能读取一行,在this.listBox1.Items.Add(str);语句后加上一条语句str = sr.ReadLine();试试吧! System.IO.File.ReadAllText(path, Encoding.GetEncoding("gb2312")); string fName = openFileDialog.FileName; string path = fName; StreamReader sr = new StreamReader(path, Encoding.GetEncoding("GB2312"));//读取文件 string str = sr.ReadToEnd();string[] strs = str.Split(System.Environment.NewLine); //或者根据其他条件分隔, foreach(string strTemp in strs)//判断行 { if (strTemp.IsNullOrEmpty() ||this.listBox1.Items.Contains(strTemp)) continue; this.listBox1.Items.Add(strTemp); } C# CS的控件设计 C# asp.net mvc 传中文参数问题 求制作酒店管理系统房态图的工具 多层应用问题 自动提取文件,实现分割问题,求救高手!! C#中多线程锁定问题 C#调用COM+老出错。。。真愁人啊! TreeView,父节点勾选,子节点自动全部勾选 Net的严重问题 C#中的Timer问题 正则匹配问题
str = sr.ReadLine();
试试吧!
StreamReader sr = new StreamReader(path, Encoding.GetEncoding("GB2312"));//读取文件
string str = sr.ReadToEnd();
string[] strs = str.Split(System.Environment.NewLine); //或者根据其他条件分隔, foreach(string strTemp in strs)//判断行
{
if (strTemp.IsNullOrEmpty() ||this.listBox1.Items.Contains(strTemp)) continue;
this.listBox1.Items.Add(strTemp);
}