나는 정수 파일이 있습니다. 첫 번째 숫자 - 후속 숫자의 수 이 파일을 배열로 가져 오는 가장 쉬운 방법은 입니까? C#파일을 배열로 가져 오는 가장 쉬운 방법은 무엇입니까? - C#
실시 예 1 : 8 1 2 3 4 5 6 7 8
예 2 4 1 2 3 0
예 3 3 0 0 1
나는 정수 파일이 있습니다. 첫 번째 숫자 - 후속 숫자의 수 이 파일을 배열로 가져 오는 가장 쉬운 방법은 입니까? C#파일을 배열로 가져 오는 가장 쉬운 방법은 무엇입니까? - C#
실시 예 1 : 8 1 2 3 4 5 6 7 8
예 2 4 1 2 3 0
예 3 3 0 0 1
int[] numbers = File
.ReadAllText("test.txt")
.Split(' ')
.Select(int.Parse)
.Skip(1)
.ToArray();
또는 만약 파일 경우
int[] numbers = File
.ReadAllLines("test.txt")
.Select(int.Parse)
.Skip(1)
.ToArray();
int[] numbers = File
.ReadAllLines("test.txt")
.First()
.Split(" ")
.Skip(1)
.Select(int.Parse)
.ToArray();
: 줄에 번호를 가지고 당신은 내가이 게시 한 후 업데이트 된이
static void Main()
{
//
// Read in a file line-by-line, and store it all in a List.
//
List<int> list = new List<int>();
using (StreamReader reader = new StreamReader("file.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
list.Add(Convert.ToInt16(line)); // Add to list.
Console.WriteLine(line); // Write to console.
}
}
int[] numbers = list.toArray();
}
확인, 포스트처럼 읽을 수 있지만 :)
대단히 감사합니다! – Alexry
편집하십시오 불구하고 일부 도움이 될 것보다, (서로에서) 열 스타일의 모든 숫자로 구성 텍스트 파일이 어떻게 보이는지에 대한 질문, 쉼표로 구분 된 줄 바꿈, 탭 구분 ... – Snake
도움이된다면 나는 비슷한 질문을했습니다 : http://stackoverflow.com/questions/2290254/read-text-data- from-file-using-linq –
숫자는 이진 형식으로 저장되어 있습니까? 아니면 각 줄을 정수로 해석 할 수있는 텍스트 파일입니까? –