StringReader 클래스

정의

문자열에서 읽는 것을 구현합니다 TextReader .

public ref class StringReader : System::IO::TextReader
public class StringReader : System.IO.TextReader
[System.Serializable]
public class StringReader : System.IO.TextReader
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class StringReader : System.IO.TextReader
type StringReader = class
    inherit TextReader
[<System.Serializable>]
type StringReader = class
    inherit TextReader
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type StringReader = class
    inherit TextReader
Public Class StringReader
Inherits TextReader
상속
StringReader
상속
특성

예제

다음 예제에서는 전체 문자열을 비동기적으로 읽는 방법을 보여줍니다.

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            ReadCharacters();
        }

        static async void ReadCharacters()
        {
            StringBuilder stringToRead = new StringBuilder();
            stringToRead.AppendLine("Characters in 1st line to read");
            stringToRead.AppendLine("and 2nd line");
            stringToRead.AppendLine("and the end");

            using (StringReader reader = new StringReader(stringToRead.ToString()))
            {
                string readText = await reader.ReadToEndAsync();
                Console.WriteLine(readText);
            }
        }
    }
}
// The example displays the following output:
//
// Characters in 1st line to read
// and 2nd line
// and the end
//
Imports System.IO
Imports System.Text

Module Module1

    Sub Main()
        ReadCharacters()
    End Sub

    Async Sub ReadCharacters()
        Dim stringToRead = New StringBuilder()
        stringToRead.AppendLine("Characters in 1st line to read")
        stringToRead.AppendLine("and 2nd line")
        stringToRead.AppendLine("and the end")

        Using reader As StringReader = New StringReader(stringToRead.ToString())
            Dim readText As String = Await reader.ReadToEndAsync()
            Console.WriteLine(readText)
        End Using
    End Sub
End Module
' The example displays the following output:
'
' Characters in 1st line to read
' and 2nd line
' and the end
'

설명

StringReader 를 사용하면 문자열을 동기적으로 또는 비동기적으로 읽을 수 있습니다. 문자는 메서드 또는 ReadAsync 메서드를 사용하여 한 번에 Read 한 줄, 메서드 또는 ReadLineAsync 메서드를 사용하여 ReadLine 한 번에 한 줄, 또는 메서드를 사용하여 전체 문자열을 ReadToEndReadToEndAsync 읽을 수 있습니다.

메모

이 형식은 인터페이스를 IDisposable 구현하지만 실제로 삭제할 리소스가 없습니다. 즉, Dispose() 직접 호출하거나 using(C#) 또는 Using(Visual Basic)와 같은 언어 구문을 사용하여 삭제할 필요가 없습니다.

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

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

File.AppendText

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

생성자

Name Description
StringReader(String)

지정된 문자열에서 읽는 클래스의 StringReader 새 인스턴스를 초기화합니다.

메서드

Name Description
Close()

를 닫습니다 StringReader.

CreateObjRef(Type)

원격 개체와 통신하는 데 사용되는 프록시를 생성하는 데 필요한 모든 관련 정보를 포함하는 개체를 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Dispose()

개체에서 사용하는 모든 리소스를 해제합니다 TextReader .

(다음에서 상속됨 TextReader)
Dispose(Boolean)

관리되지 않는 리소스를 StringReader 해제하고 관리되는 리소스를 선택적으로 해제합니다.

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetLifetimeService()

이 인스턴스의 수명 정책을 제어하는 현재 수명 서비스 개체를 검색합니다.

(다음에서 상속됨 MarshalByRefObject)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
InitializeLifetimeService()

이 인스턴스의 수명 정책을 제어하는 수명 서비스 개체를 가져옵니다.

(다음에서 상속됨 MarshalByRefObject)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
MemberwiseClone(Boolean)

현재 MarshalByRefObject 개체의 단순 복사본을 만듭니다.

(다음에서 상속됨 MarshalByRefObject)
Peek()

사용 가능한 다음 문자를 반환하지만 사용하지 않습니다.

Read()

입력 문자열에서 다음 문자를 읽고 문자 위치를 한 문자씩 앞으로 이동합니다.

Read(Char[], Int32, Int32)

입력 문자열에서 문자 블록을 읽고 문자 위치를 다음으로 count이동합니다.

Read(Span<Char>)

현재 위치에서 시작하여 입력 문자열에서 모든 문자를 읽고 현재 위치를 입력 문자열의 끝으로 진행합니다.

ReadAsync(Char[], Int32, Int32)

현재 문자열에서 지정된 최대 문자 수를 비동기적으로 읽고 지정된 인덱스에서 시작하여 버퍼에 데이터를 씁니다.

ReadAsync(Memory<Char>, CancellationToken)

현재 위치에서 시작하여 입력 문자열의 모든 문자를 비동기적으로 읽고 현재 위치를 입력 문자열의 끝으로 진행합니다.

ReadBlock(Char[], Int32, Int32)

현재 텍스트 판독기에서 지정된 최대 문자 수를 읽고 지정된 인덱스에서 시작하여 버퍼에 데이터를 씁니다.

(다음에서 상속됨 TextReader)
ReadBlock(Span<Char>)

현재 위치에서 시작하여 입력 문자열에서 모든 문자를 읽고 현재 위치를 입력 문자열의 끝으로 진행합니다.

ReadBlockAsync(Char[], Int32, Int32)

현재 문자열에서 지정된 최대 문자 수를 비동기적으로 읽고 지정된 인덱스에서 시작하여 버퍼에 데이터를 씁니다.

ReadBlockAsync(Memory<Char>, CancellationToken)

현재 위치에서 시작하여 입력 문자열의 모든 문자를 비동기적으로 읽고 현재 위치를 입력 문자열의 끝으로 진행합니다.

ReadLine()

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

ReadLineAsync()

현재 문자열에서 문자 줄을 비동기적으로 읽고 데이터를 문자열로 반환합니다.

ReadToEnd()

현재 위치에서 문자열의 끝까지 모든 문자를 읽고 단일 문자열로 반환합니다.

ReadToEndAsync()

현재 위치에서 문자열 끝까지 모든 문자를 비동기적으로 읽고 단일 문자열로 반환합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
IDisposable.Dispose()

이 멤버에 대한 설명은 을 참조하세요 Dispose().

(다음에서 상속됨 TextReader)

적용 대상

추가 정보