static void Main(string[] args)
{
string fn = @"D:\test.txt";
int[,] nums = new int[3, 4];
using (StreamReader sr = new StreamReader(fn))
{
string all = sr.ReadToEnd();
int i = 0;
int j = 0;
foreach (string line in all.Split(new char[] { '\r', '\n' },
StringSplitOptions.RemoveEmptyEntries))
{
foreach (string w in line.Split(new char[] { ' ' },
StringSplitOptions.RemoveEmptyEntries))
{
nums[i, j] = Convert.ToInt32(w);//最终结果
Console.Write(w + '\t');
}
i++;
j = 0;
Console.WriteLine();
}
}
Console.ReadLine();
}
有个方法是读到文档结尾的,split("/n"),差不多是这么个意思。
你这是要转为二维数组?