读取已经可以,并且用message可以,但是textBox上为什么就显示不出来呢? int num0;
string sc = null;
string[] wc = new string[1000];
string filePath = Application.StartupPath + @"\word.txt";
using (StreamReader sr = new StreamReader(filePath, System.Text.Encoding.GetEncoding("gb2312")))
{
while ((sc = sr.ReadLine()) != null)
{
wc[num] = sc;
textBox.Text = wc[num];
//MessageBox.Show(sr.ReadLine().ToString());
num++;
if (num > 300)
{sr.Close(); }
}
}
txt里是汉字,300行~~
string sc = null;
string[] wc = new string[1000];
string filePath = Application.StartupPath + @"\word.txt";
using (StreamReader sr = new StreamReader(filePath, System.Text.Encoding.GetEncoding("gb2312")))
{
while ((sc = sr.ReadLine()) != null)
{
wc[num] = sc;
textBox.Text = wc[num];
//MessageBox.Show(sr.ReadLine().ToString());
num++;
if (num > 300)
{sr.Close(); }
}
}
txt里是汉字,300行~~
解决方案 »
- 怎么让PictureBox拍的相片居中
- 请问C# 如何调用DLL中类的方法?
- System.IO.File 无法操作如"\\.\C:\"的路径,如何解决
- 请教高手:我用vs2005和sql 2005开发的windows应用程序如何制作安装程序(打包)?
- 简单问题:除了用循环,如何将 datatable 源表的 其中1列(column) 复制到一个新的 目标表中
- 如何像优化大师那样用C# 得到 软硬件信息?
- Dev控件GridControl,怎样复制选中行焦点单元格的值?
- 关于Pocket PC 2002的一些简单问题
- 有关程序编译调试的问题?
- 配置文件app.config
- 用C#如何控制io接口
- C#退出程序问题
用StringBuilder拼接字符串
\r\n换行
你好,readtoend 我用了,但是读出来的都是拼接好多字的,btw,我读文件是没有问题的,问题出现在textbox不显示上~~
string sc = null;
string filePath = Application.StartupPath + @"\word.txt";
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(filePath, System.Text.Encoding.GetEncoding("gb2312")))
{
while ((sc = sr.ReadLine()) != null)
{
sb.Append(sc);
num++;
if (num > 300)
{sr.Close(); }
}
textBox.Text = sb.ToString();
}其实这样更简单
string str = File.ReadAllText(Application.StartupPath + @"\word.txt");
textBox.Text = str;
再说Multiline我已经设成true了
F11 单步查看值
string str=File.ReadAllText(Application.StartupPath + @"\word.txt")
int num0;
string sc = null;
string[] wc = new string[1000];
string filePath = Application.StartupPath + @"\word.txt";
using (StreamReader sr = new StreamReader(filePath, System.Text.Encoding.GetEncoding("gb2312")))
{
while ((sc = sr.ReadLine()) != null)
{
wc[num] = sc;
num++;
if (num > 300) {sr.Close(); }
}
}int index = 0;
textBox.Text = wc[index];...// 在显示下一条按钮的Click事件中
index++;
textBox.Text = wc[index];
if(index > 300) return;// 读取的时候只要300条,这边可以按需要处理//index和wc提到外部就可以了