-7
모두가 무엇입니까 최대텍스트 파일을 배열로 읽는 방법은 무엇입니까?
내 코드 에서이 문제가 있고 텍스트 파일에서 읽는 방법을 알아낼 수 및 C# 2 중 배열 [1024,8] 2 차원 배열에 넣을 수 없습니다.
0 148.9 19.4 20.2 112.6 41.9 205.7 46.7 87.2
1 41.4 97.1 86.4 102.5 99.1 183.1 47.7 84.0
2 154.8 303.1 252.2 110.7 74.5 59.7 193.7 361.6
.
.
1023 40.8 136.8 222.1 39.5 104.9 35.3 76.0 111.4
나는 라인으로이 파일 라인을 읽으려고하지만,이 방법은 코드가 깔끔 보인다 나에게
static void Main(string[] args)
{
int counter = 0;
string line;
double[] task = new double[8];
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
//int count = 0;
while ((line = file.ReadLine()) != null && counter <= 1023)
{
//count++;
//Console.WriteLine(count);
string[] numbers = new string[8];
int numCount = 0;
for (int i = 0; i < line.Length; i++)
{
if (line[i] != ' ')
{
numbers[numCount] = "";
while (line[i] != ' ')
{
numbers[numCount] += line[i];
i++;
}
numCount++;
}
}
for (int i = 0; i < 8; i++)
{
task[i] = Convert.ToDouble(numbers[i]);
}
counter++;
Console.WriteLine("The array contain:");
for (int i = 0; i < 8; i++)
Console.WriteLine(task[i]);
}
file.Close();
// Suspend the screen.
Console.ReadLine();
}
당신은 문제가 무엇에 직면하고있다을 배치? 지금까지 뭐 해봤 어? –
아, 코드가 있습니다! 우리가 시도한 것을 보여줘! –
'TextReader.ReadLine'을 사용하여 행의 값을 배열에 추가합니다. – Aphelion