当前位置:编程学习 > C#/ASP.NET >>

菜鸟求大神解决啊 按钮点击事件导入TXT文本。

刚接触C#不就啊。然后现在做的一个小玩具。需要导入txt文件。然后需要用数组分割,比如我的文本如下应该怎么导入
123456
123456
123456
123456
每一行的数据都不同。但是字数相同。导入到文本框里面。通过openfliedialog
具体代码应该怎么写啊 --------------------编程问答-------------------- 大神在哪里 --------------------编程问答--------------------

richTextBox1.Lines = File.ReadAllLines(openFileDialog1.FileName);
--------------------编程问答--------------------
引用 2 楼 ojlovecd 的回复:

richTextBox1.Lines = File.ReadAllLines(openFileDialog1.FileName);
+1 --------------------编程问答-------------------- 那怎么加入到数组啊0.0我要把那些数据加入到数组。

引用 2 楼 ojlovecd 的回复:

richTextBox1.Lines = File.ReadAllLines(openFileDialog1.FileName);
--------------------编程问答--------------------
引用 4 楼 aa494633528 的回复:
那怎么加入到数组啊0.0我要把那些数据加入到数组。

Quote: 引用 2 楼 ojlovecd 的回复:


richTextBox1.Lines = File.ReadAllLines(openFileDialog1.FileName);

File.ReadAllLines(openFileDialog1.FileName)返回的就是个数组啊…… --------------------编程问答-------------------- 这个书上应该有讲的吧。或者百度一下就有了。 --------------------编程问答--------------------         private void button3_Click(object sender, EventArgs e)
        {
            
                openFileDialog1.Filter = "文本(*.txt)|*.txt|全部文件(*.*)|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {                     write(openFileDialog1.FileName);
                }             
        }
        private void write(string filename)
        {
            StreamReader reader = new StreamReader(filename, System.Text.Encoding.Default);//获取默认编码 
            String linestr = reader.ReadLine();             while (linestr != null)
            {
                if ((1 <= linestr.Length) & (linestr.Length <= 30))
                {
                    this.textBox3.AppendText(linestr + Environment.NewLine);                 }
                linestr = reader.ReadLine();
            }             reader.Close();
            string[] KbSkySZ;
            KbSkySZ = Regex.Split(this.textBox3.Text, Environment.NewLine, RegexOptions.Multiline | RegexOptions.Singleline);
            KbSkyCount = KbSkySZ.Length;
        }

我朋友是这样子写的0.0 --------------------编程问答--------------------
引用 7 楼 aa494633528 的回复:
        private void button3_Click(object sender, EventArgs e)
        {
            
                openFileDialog1.Filter = "文本(*.txt)|*.txt|全部文件(*.*)|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {                     write(openFileDialog1.FileName);
                }             
        }
        private void write(string filename)
        {
            StreamReader reader = new StreamReader(filename, System.Text.Encoding.Default);//获取默认编码 
            String linestr = reader.ReadLine();             while (linestr != null)
            {
                if ((1 <= linestr.Length) & (linestr.Length <= 30))
                {
                    this.textBox3.AppendText(linestr + Environment.NewLine);                 }
                linestr = reader.ReadLine();
            }             reader.Close();
            string[] KbSkySZ;
            KbSkySZ = Regex.Split(this.textBox3.Text, Environment.NewLine, RegexOptions.Multiline | RegexOptions.Singleline);
            KbSkyCount = KbSkySZ.Length;
        }

我朋友是这样子写的0.0

一句话就能搞定的事情非要重复造轮子…… --------------------编程问答--------------------
引用 5 楼 ojlovecd 的回复:
Quote: 引用 4 楼 aa494633528 的回复:

那怎么加入到数组啊0.0我要把那些数据加入到数组。

Quote: 引用 2 楼 ojlovecd 的回复:


richTextBox1.Lines = File.ReadAllLines(openFileDialog1.FileName);

File.ReadAllLines(openFileDialog1.FileName)返回的就是个数组啊……


+1
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,