StringWriter 클래스

정의

문자열에 TextWriter 정보를 쓰는 방법을 구현합니다. 정보는 기본에 저장됩니다 StringBuilder.

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

예제

다음 코드 예제에서는 이중 간격 문장 그룹에서 연속 단락을 만든 다음 단락을 원래 텍스트로 다시 변환하는 방법을 보여 줍니다.

using System;
using System.IO;

class StringRW
{
    static void Main()
    {
        string textReaderText = "TextReader is the abstract base " +
            "class of StreamReader and StringReader, which read " +
            "characters from streams and strings, respectively.\n\n" +

            "Create an instance of TextReader to open a text file " +
            "for reading a specified range of characters, or to " +
            "create a reader based on an existing stream.\n\n" +

            "You can also use an instance of TextReader to read " +
            "text from a custom backing store using the same " +
            "APIs you would use for a string or a stream.\n\n";

        Console.WriteLine("Original text:\n\n{0}", textReaderText);

        // 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);

        // Re-create textReaderText from aParagraph.
        int intCharacter;
        char convertedCharacter;
        StringWriter strWriter = new StringWriter();
        strReader = new StringReader(aParagraph);
        while(true)
        {
            intCharacter = strReader.Read();

            // Check for the end of the string
            // before converting to a character.
            if(intCharacter == -1) break;

            convertedCharacter = (char)intCharacter;
            if(convertedCharacter == '.')
            {
                strWriter.Write(".\n\n");

                // Bypass the spaces between sentences.
                strReader.Read();
                strReader.Read();
            }
            else
            {
                strWriter.Write(convertedCharacter);
            }
        }
        Console.WriteLine("\nOriginal text:\n\n{0}",
            strWriter.ToString());
    }
}
Option Explicit
Option Strict

Imports System.IO

Public Class StrReader

    Shared Sub Main()
    
        Dim textReaderText As String = "TextReader is the " & _
            "abstract base class of StreamReader and " & _
            "StringReader, which read characters from streams " & _
            "and strings, respectively." & _
            vbCrLf & vbCrLf & _
            "Create an instance of TextReader to open a text " & _
            "file for reading a specified range of characters, " & _
            "or to create a reader based on an existing stream." & _
            vbCrLf & vbCrLf & _
            "You can also use an instance of TextReader to read " & _
            "text from a custom backing store using the same " & _
            "APIs you would use for a string or a stream." & _
            vbCrLf & vbCrLf

        Console.WriteLine("Original text:" & vbCrLf & vbCrLf & _
            textReaderText)

        ' 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)
    
        ' Re-create textReaderText from aParagraph.
        Dim intCharacter As Integer 
        Dim convertedCharacter As Char 
        Dim strWriter As New StringWriter()
        strReader = New StringReader(aParagraph)
        While True
            intCharacter = strReader.Read()

            ' Check for the end of the string 
            ' before converting to a character.
            If intCharacter = -1 Then
                Exit While
            End If

            convertedCharacter = Convert.ToChar(intCharacter)
            If convertedCharacter = "."C Then
                strWriter.Write("." & vbCrLf & vbCrLf)

                ' Bypass the spaces between sentences.
                strReader.Read()
                strReader.Read()
            Else
                strWriter.Write(convertedCharacter)
            End If
        End While
        Console.WriteLine(vbCrLf & "Original text:" & vbCrLf & _ 
            vbCrLf & strWriter.ToString())

    End Sub
End Class

설명

StringWriter 를 사용하면 문자열에 동기적으로 또는 비동기적으로 쓸 수 있습니다. 또는 메서드를 사용하여 한 번에 Write(Char)WriteAsync(Char) 문자, 또는 메서드를 사용하여 한 번에 문자열을 Write(String) 작성할 WriteAsync(String) 수 있습니다. 또한 문자, 문자 배열 또는 문자열을 작성한 다음 메서드 중 하나를 사용하여 줄 종결자를 비동기적으로 작성할 WriteLineAsync 수 있습니다.

메모

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

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

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

File.AppendText

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

생성자

Name Description
StringWriter()

StringWriter 클래스의 새 인스턴스를 초기화합니다.

StringWriter(IFormatProvider)

지정된 형식 컨트롤을 사용하여 클래스의 StringWriter 새 인스턴스를 초기화합니다.

StringWriter(StringBuilder, IFormatProvider)

지정된 StringBuilder 형식 공급자에 쓰고 지정된 형식 공급자가 있는 클래스의 StringWriter 새 인스턴스를 초기화합니다.

StringWriter(StringBuilder)

지정된 StringBuilder클래스에 쓰는 클래스의 StringWriter 새 인스턴스를 초기화합니다.

필드

Name Description
CoreNewLine

TextWriter사용되는 줄 바꿈 문자를 저장합니다.

(다음에서 상속됨 TextWriter)

속성

Name Description
Encoding

출력이 Encoding 기록되는 값을 가져옵니다.

FormatProvider

서식을 제어하는 개체를 가져옵니다.

(다음에서 상속됨 TextWriter)
NewLine

현재 TextWriter에서 사용하는 줄 종결자 문자열을 가져오거나 설정합니다.

(다음에서 상속됨 TextWriter)

메서드

Name Description
Close()

현재 StringWriter 스트림과 기본 스트림을 닫습니다.

CreateObjRef(Type)

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

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

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

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

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

DisposeAsync()

개체에서 사용하는 TextWriter 모든 리소스를 비동기적으로 해제합니다.

(다음에서 상속됨 TextWriter)
Equals(Object)

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

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

현재 기록기에 대한 모든 버퍼를 지우고 버퍼링된 데이터가 기본 디바이스에 기록되도록 합니다.

(다음에서 상속됨 TextWriter)
FlushAsync()

현재 기록기에 대한 모든 버퍼를 비동기적으로 지우고 버퍼링된 데이터가 기본 디바이스에 기록되도록 합니다.

GetHashCode()

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

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

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

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

기본 StringBuilder.

GetType()

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

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

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

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

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

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

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

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

지금까지 현재 StringWriter 에 기록된 문자가 포함된 문자열을 반환합니다.

Write(Boolean)

값의 텍스트 표현을 Boolean 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
Write(Char)

문자열에 문자를 씁니다.

Write(Char[], Int32, Int32)

문자열에 문자의 하위 배열을 씁니다.

Write(Char[])

텍스트 스트림에 문자 배열을 씁니다.

(다음에서 상속됨 TextWriter)
Write(Decimal)

10진수 값의 텍스트 표현을 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
Write(Double)

8 바이트 부동 소수점 값의 텍스트 표현을 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
Write(Int32)

텍스트 스트림에 부가된 4 바이트 정수의 텍스트 표현을 씁니다.

(다음에서 상속됨 TextWriter)
Write(Int64)

텍스트 스트림에 부가된 8 바이트 정수의 텍스트 표현을 씁니다.

(다음에서 상속됨 TextWriter)
Write(Object)

해당 개체에서 메서드를 호출하여 개체의 텍스트 표현을 ToString 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
Write(ReadOnlySpan<Char>)

현재 문자열에 문자 범위의 문자열 표현을 씁니다.

Write(Single)

4 바이트 부동 소수점 값의 텍스트 표현을 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
Write(String, Object, Object, Object)

메서드와 동일한 의미 체계를 사용하여 서식이 지정된 문자열을 텍스트 스트림에 Format(String, Object, Object, Object) 씁니다.

(다음에서 상속됨 TextWriter)
Write(String, Object, Object)

메서드와 동일한 의미 체계를 사용하여 서식이 지정된 문자열을 텍스트 스트림에 Format(String, Object, Object) 씁니다.

(다음에서 상속됨 TextWriter)
Write(String, Object)

메서드와 동일한 의미 체계를 사용하여 서식이 지정된 문자열을 텍스트 스트림에 Format(String, Object) 씁니다.

(다음에서 상속됨 TextWriter)
Write(String, Object[])

메서드와 동일한 의미 체계를 사용하여 서식이 지정된 문자열을 텍스트 스트림에 Format(String, Object[]) 씁니다.

(다음에서 상속됨 TextWriter)
Write(String)

현재 문자열에 문자열을 씁니다.

Write(UInt32)

4 바이트 부호 없는 정수의 텍스트 표현을 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
Write(UInt64)

8 바이트 부호 없는 정수의 텍스트 표현을 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
WriteAsync(Char)

문자열에 문자를 비동기적으로 씁니다.

WriteAsync(Char[], Int32, Int32)

문자열에 문자의 하위 배열을 비동기적으로 씁니다.

WriteAsync(Char[])

문자 배열을 텍스트 스트림에 비동기적으로 씁니다.

(다음에서 상속됨 TextWriter)
WriteAsync(ReadOnlyMemory<Char>, CancellationToken)

문자열에 문자의 메모리 영역을 비동기적으로 씁니다.

WriteAsync(String)

문자열을 현재 문자열에 비동기적으로 씁니다.

WriteLine()

텍스트 스트림에 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Boolean)

값의 Boolean 텍스트 표현을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Char)

텍스트 스트림에 문자를 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Char[], Int32, Int32)

문자의 하위 배열을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Char[])

문자 배열을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Decimal)

10진수 값의 텍스트 표현을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Double)

8 바이트 부동 소수점 값의 텍스트 표현을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Int32)

텍스트 스트림에 부호 있는 4 바이트 정수의 텍스트 표현과 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Int64)

텍스트 스트림에 부호 있는 8 바이트 정수의 텍스트 표현과 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(Object)

해당 개체의 메서드를 호출한 다음 줄 종결자를 호출 ToString 하여 개체의 텍스트 표현을 텍스트 스트림에 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(ReadOnlySpan<Char>)

텍스트 표현을 문자열에 문자 범위와 줄 종결자를 씁니다.

WriteLine(Single)

4 바이트 부동 소수점 값의 텍스트 표현을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(String, Object, Object, Object)

와 동일한 의미 체계를 사용하여 서식이 지정된 문자열과 새 줄을 텍스트 스트림에 씁니다 Format(String, Object).

(다음에서 상속됨 TextWriter)
WriteLine(String, Object, Object)

메서드와 동일한 의미 체계를 사용하여 서식이 지정된 문자열과 새 줄을 텍스트 스트림에 Format(String, Object, Object) 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(String, Object)

메서드와 동일한 의미 체계를 사용하여 서식이 지정된 문자열과 새 줄을 텍스트 스트림에 Format(String, Object) 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(String, Object[])

와 동일한 의미 체계를 사용하여 서식이 지정된 문자열과 새 줄을 텍스트 스트림에 씁니다 Format(String, Object).

(다음에서 상속됨 TextWriter)
WriteLine(String)

문자열을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(UInt32)

4 바이트 부호 없는 정수의 텍스트 표현을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLine(UInt64)

8 바이트 부호 없는 정수의 텍스트 표현을 텍스트 스트림에 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLineAsync()

텍스트 스트림에 줄 종결자를 비동기적으로 씁니다.

(다음에서 상속됨 TextWriter)
WriteLineAsync(Char)

문자열에 문자를 비동기적으로 쓴 다음 줄 종결자를 씁니다.

WriteLineAsync(Char[], Int32, Int32)

문자열에 문자 하위 배열을 비동기적으로 쓴 다음 줄 종결자를 씁니다.

WriteLineAsync(Char[])

문자 배열을 텍스트 스트림에 비동기적으로 쓴 다음 줄 종결자를 씁니다.

(다음에서 상속됨 TextWriter)
WriteLineAsync(ReadOnlyMemory<Char>, CancellationToken)

문자의 메모리 영역에 대한 문자열 표현을 현재 문자열에 비동기적으로 쓴 다음 줄 종결자를 씁니다.

WriteLineAsync(String)

문자열을 현재 문자열에 비동기적으로 쓴 다음 줄 종결자를 씁니다.

명시적 인터페이스 구현

Name Description
IDisposable.Dispose()

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

(다음에서 상속됨 TextWriter)

확장명 메서드

Name Description
ConfigureAwait(IAsyncDisposable, Boolean)

비동기 삭제 가능 파일에서 반환된 작업에 대한 대기가 수행되는 방법을 구성합니다.

적용 대상

추가 정보