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

用C#如何将C盘目录下的某个txt文件读取并储存为二维数组

求各位大神帮帮忙,刚接触C#:
    1、需要在C盘目录下寻找某个名字的txt文本,并选择读取。(就像我们平时在程序里选择打开文件功能)
    2、txt数据如下(数据之间有一个空格,其他顶行排列)
1 2
2 3
3 4
    3、将其转换成二维数组,便于下面程序的调用计算。

麻烦给出详细的程序示例或者截图。
谢谢! --------------------编程问答-------------------- string[][] data = System.IO.File.ReadAllLines("C:\\1.txt").Select(x => x.Split(' ')).ToArray(); --------------------编程问答-------------------- 打开文件可以用OpenFileDialog

OpenFileDialog ofn = new OpenFileDialog();
if (ofn.ShowDialog() == DialogResult.OK)
{
    string[][] data = System.IO.File.ReadAllLines(ofn.FileName).Select(x => x.Split(' ')).ToArray();
    ...
} --------------------编程问答-------------------- 你要有个心理准备,找一这样的文件,需要耗时8个小时。 --------------------编程问答-------------------- “详细的程序示例或者截图”这个要求无法满足你。csdn是一个论坛而已,不是给人免费做项目的。所以关键是交换关键的意见,仅此而已。 --------------------编程问答--------------------
 string resultFile;           
              string[] arr = null;
              if (openFileDialog1.ShowDialog() == DialogResult.OK)
              {
                  resultFile = openFileDialog1.FileName;
                  string[] allstr = File.ReadAllLines(resultFile, Encoding.Default);                 
                  int first = allstr.Length;
                  string[][] strlist = new string[first][];
                  for (int i = 0; i < allstr.Length; i++)
                  {
                      arr = allstr[i].Split(' ');
                      strlist[i] = new string[arr.Length];
                      for (int j = 0; j < arr.Length; j++)
                      {
                          strlist[i][j] = arr[j];

                      }
                  }
                  MessageBox.Show(strlist[3][0].ToString());

              }
--------------------编程问答-------------------- 明白,谢谢各位大神!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,