第2个回答 推荐于2018-03-29
从文件中读取字符串到数组中 02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 0f
02 03 03 01 04 0f 0s 0g 0a 12
文件D:\123.txt中有如上数据(string型)
怎样复制到string数组a[10,10]中
谢谢
C#语言描述.
最佳答案
using System.IO;StreamReader sr = new StreamReader(@"D:\123.txt");
string tempStr = sr.ReadToEnd();
string[][] a = new string[10,10];
//根据,分开
string[] strs = tempStr.Split(new char[] { ' ,' });
int tempIndex =0;
for (int i = 0; i < 10; i++)
{
for (int j= 0;j < 10; j++)
{
a[i][j] = strs[tempIndex];
tempIndex++;
}本回答被网友采纳