StringReader.ReadLine 메서드

정의

현재 문자열에서 한 줄의 문자를 읽고 데이터를 문자열로 반환합니다.

public:
 override System::String ^ ReadLine();
public override string ReadLine ();
public override string? ReadLine ();
override this.ReadLine : unit -> string
Public Overrides Function ReadLine () As String

반환

현재 문자열의 다음 줄 또는 문자열의 끝에 도달한 경우 null입니다.

예외

현재 판독기가 닫힌 경우

메모리가 부족하여 반환된 문자열의 버퍼를 할당할 수 없습니다.

예제

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 StringReader 클래스입니다.

// From textReaderText, create a continuous paragraph 
// with two spaces between each sentence.
   String^ aLine;
String^ aParagraph;
StringReader^ strReader = gcnew StringReader( textReaderText );
while ( true )
{
   aLine = strReader->ReadLine();
   if ( aLine != nullptr )
   {
      aParagraph = String::Concat( aParagraph, aLine,  " " );
   }
   else
   {
      aParagraph = String::Concat( aParagraph,  "\n" );
      break;
   }
}

Console::WriteLine(  "Modified text:\n\n{0}", aParagraph );
// From textReaderText, create a continuous paragraph
// with two spaces between each sentence.
string aLine, aParagraph = null;
StringReader strReader = new StringReader(textReaderText);
while(true)
{
    aLine = strReader.ReadLine();
    if(aLine != null)
    {
        aParagraph = aParagraph + aLine + " ";
    }
    else
    {
        aParagraph = aParagraph + "\n";
        break;
    }
}
Console.WriteLine("Modified text:\n\n{0}", aParagraph);
' From textReaderText, create a continuous paragraph 
' with two spaces between each sentence.
Dim aLine, aParagraph As String
Dim strReader As New StringReader(textReaderText)
While True
    aLine = strReader.ReadLine()
    If aLine Is Nothing Then
        aParagraph = aParagraph & vbCrLf
        Exit While
    Else
        aParagraph = aParagraph & aLine & " "
    End If
End While
Console.WriteLine("Modified text:" & vbCrLf & vbCrLf & _ 
    aParagraph)

설명

이 메서드를 재정의 합니다 TextReader.ReadLine 메서드.

줄은 줄 바꿈("\n"), 캐리지 리턴("\r"), 캐리지 리턴 바로 뒤에 줄 바꿈("\r\n") 또는 스트림 끝 마커가 오는 문자 시퀀스로 정의됩니다. 반환되는 문자열에는 종료 캐리지 리턴 또는 줄 바꿈이 포함되어 있지 않습니다. 반환된 값은 null 스트림 끝 표식에 도달한 경우 입니다. 즉, 마지막 줄 읽기와 스트림 끝 마커 사이에 아무 것도 없는 경우 메서드는 를 반환합니다 null.

현재 메서드가 을 OutOfMemoryExceptionthrow하는 경우 기본 문자열의 판독기 위치는 메서드가 읽을 수 있는 문자 수만큼 고급이지만 내부 ReadLine 버퍼로 이미 읽은 문자는 삭제됩니다. 문자열의 판독기 위치를 변경할 수 없으므로 이미 읽은 문자는 복구할 수 없으며 를 다시 초기화 StringReader해야만 액세스할 수 있습니다. 이러한 상황을 방지하려면 메서드를 Read 사용하고 미리 할당된 버퍼에 읽기 문자를 저장합니다.

다음 표에서는 다른 일반적인 또는 관련 I/O 작업의 예를 나열합니다.

수행할 작업 이 항목의 예제를 참조하세요.
텍스트 파일을 만듭니다. 방법: 파일에 텍스트 쓰기
텍스트 파일에 씁니다. 방법: 파일에 텍스트 쓰기
텍스트 파일에서 읽습니다. 방법: 파일에서 텍스트 읽기
파일에 텍스트를 추가합니다. 방법: 로그 파일 열기 및 추가

File.AppendText

FileInfo.AppendText
파일의 크기를 가져옵니다. FileInfo.Length
파일의 특성을 가져옵니다. File.GetAttributes
파일의 특성을 설정합니다. File.SetAttributes
파일이 있는지 확인합니다. File.Exists
이진 파일에서 읽습니다. 방법: 새로 만든 데이터 파일 읽기 및 쓰기
이진 파일에 씁니다. 방법: 새로 만든 데이터 파일 읽기 및 쓰기

적용 대상

추가 정보