나는 컴퓨터 과정을 위해 콘솔 응용 프로그램을 작성해야합니다. 이 프로그램은 StreamReader를 사용하여 파일에서 텍스트를 읽고 문자열을 단일 단어로 분할하여 문자열 배열에 저장 한 다음 그 단어를 역방향으로 인쇄합니다.StreamReader가 캐리지 리턴으로 읽지 않습니다.
파일에 캐리지 리턴이있을 때마다 파일에서 텍스트의 읽기가 중지됩니다. 누구든지 이걸 도와 줄 수 있니? 파일 "input.txt를"
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace Assignment2
{
class Program
{
public String[] chop(String input)
{
input = Regex.Replace(input, @"\s+", " ");
input = input.Trim();
char[] stringSeparators = {' ', '\n', '\r'};
String[] words = input.Split(stringSeparators);
return words;
}
static void Main(string[] args)
{
Program p = new Program();
StreamReader sr = new StreamReader("input.txt");
String line = sr.ReadLine();
String[] splitWords = p.chop(line);
for (int i = 1; i <= splitWords.Length; i++)
{
Console.WriteLine(splitWords[splitWords.Length - i]);
}
Console.ReadLine();
}
}
}
그리고 여기에 있습니다 : : 여기
는 메인 프로그램입니다This is the file you can use to
provide input to your program and later on open it inside your program to process the input.
Ehm ...'sr.ReadLine()'maybe? –
'null'을 반환하여 EOF를 나타낼 때까지 각 행을 차례로 처리하려면 루프에서'ReadLine()'을 호출해야합니다. –