현재 알파벳 순서가 아닌 단어의 파일을 가져오고 알파벳 순서로 정렬되도록 단어 순서를 바꿉니다 (비 내장 기능을 사용하려고합니다. sort 메서드)를 호출 한 다음 새로 정렬 된 목록을 새 txt 파일 (작성해야하는 파일)에 씁니다. 예를 들어, "dog bat apple rabbit cat"과 같이 txt 파일에 5 단어 만 있다고 가정 해 보겠습니다. 나는 프로그램을 알파벳순으로 배열하고, 그 순서를 저장하는 txt 파일을 생성하기를 원할 것이다. 지금 당장은 프로그램이 txt 파일을 반복하지만 재 배열 목록을 새 txt 파일에 저장하지 않습니다. 새 파일에 저장되는 내용은 다음과 같습니다. "System.Collections.Generic.List`1 [System.String]" 진실을 말하면, 아직 익숙하지 않아서 구조화 또는 코딩이 잘못되었다고 사과합니다. 별로 좋지 않습니다. 정렬되지 않은 원본 파일은 "jumbled english FILTERED.ALL.txt"라고하며, 쓰려는 파일의 이름은 "english FILTERED.ALL.txt"입니다.파일 읽기 및 쓰기 문제 C#
static void Main(string[] args)
{
// declaring integer for minimum.
int min = 0;
// declare the list for the original file
List<string> LinuxWords = new List<string>();
List<string> lexicalOrder = new List<string>();
// read the text from the file
string[] lines = System.IO.File.ReadAllLines("jumbled english FILTERED.ALL.txt");
string line = string.Empty;
// seperate each word into a string
//foreach (string line in lines)
//{
//add each word into the list.
//LinuxWords.Add(line);
//}
for (int i = 0; i < lines.Length - 1; i++)
{
for (int j = i + 1; j < lines.Length; j++)
{
if (lines[i].Length < lines[j].Length)
{
min = lines[i].Length;
}
else
{
min = lines[j].Length;
}
for (int k = 0; k < min; k++)
{
if (lines[i][k] > lines[j][k])
{
line = lines[i].ToString();
lines[i] = lines[j];
lines[j] = line;
break;
}
else if (lines[i][k] == lines[j][k])
{
continue;
}
else
{
break;
}
}
}
}
for (int i = 0; i < lines.Length; i++)
{
Console.WriteLine("The program is formatting the correct order");
lexicalOrder.Add(lines[i]);
}
//lexicalOrder.ForEach(Console.WriteLine);
//}
//LinuxWords.ForEach(Console.WriteLine);
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "english FILTERED.ALL.txt",
lexicalOrder.ToString());
// write the ordered list back into another .txt file named "english FILTERED.ALL.txt"
// System.IO.File.WriteAllLines("english FILTERED.ALL.txt", lexicalOrder);
Console.WriteLine("Finished");
}
'엉망인 영어 FILTERED.ALL.txt'형식이란 무엇입니까? 예를 들어 추출물을 주시겠습니까? 원하는 결과는 무엇입니까? –
* 내 코드 *로 들어갈 수 없다는 것은 무엇을 의미합니까? – Searching
크리스티 펀치 이 부저 의무를 다하는 약한 승강구 이 singingly – JimmyDean