作者qweqweqweqwe (啪)
看板C_Sharp
标题Re: [问题] 请问要如何从.txt内读取字元
时间Wed Oct 10 17:51:17 2007
※ 引述《DolphinEdwin (.)》之铭言:
: 我的问题是.txt内的档案假设为:
: 1 5 1 2
: 2 4 6 7
: 3 6 4 5
: 4 7 2 1
: 5 3 10 9
: 6 1 11 1
: 7 8 9 2
: 8 9 1 12
: 9 1 7 5
: 10 2 12 13
: 11 1 5 6
: 数字间都隔一个空格
: 假设我宣告了阵列 a[] b[] c[] d[]
: 想要让他读取并储存成为
: a[0]=1 a[1]=2 a[2]=3 a[3]=4 ...a[] 为.txt第一行
: b[0]=5 b[1]=4 b[2]=6 b[3]=7 ...b[] 为.txt第二行
: c[0]=1 c[1]=6 c[2]=4 c[3]=2 ...c[] 为.txt第三行
: d[0]=2 d[1]=7 d[2]=5 d[3]=1 ...d[] 为.txt第四行
: 请问该怎麽做呢??
: 或者是全部由左而右由上而下储存成为
: a[0]=1 a[1]=5 a[2]=1 a[3]=2
: a[4]=2 a[5]=4 a[6]=6 a[7]=7.....
: 目前我只会一次只读取1个字元的
: StreamReader sr = new StreamReader("d:\\xxx.txt");
: char[] a = new char[sr.BaseStream.Length];
: sr.Read(a, 0, a.Length);
: sr.Close();
: 不知道怎麽一次读取多个字元...
: 请各位高手帮忙了拜托拜托...
: 感激不尽
using (StreamReader str = new
StreamReader("C:\\xxx.txt",Encoding.Default))
{
String line;
line = str.ReadLine();
temp = line.Trim().Split(new char[] { ' ' });
str.Close();
}
这样..?
temp[0]=1 temp[1]=5 temp[2]=1 temp[3]=2
试试看
我没compile过QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.225.124.59
1F:→ qweqweqweqwe:忘了加 String[] temp;在最前面 10/10 18:05
2F:推 DolphinEdwin:感谢 10/12 23:21