StringWriter Class

 

Implements a TextWriter for writing information to a string. The information is stored in an underlying StringBuilder.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

System.Object
  System.MarshalByRefObject
    System.IO.TextWriter
      System.IO.StringWriter

[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type StringWriter = 
    class
        inherit TextWriter
    end

NameDescription
System_CAPS_pubmethodStringWriter()

Initializes a new instance of the StringWriter class.

System_CAPS_pubmethodStringWriter(IFormatProvider)

Initializes a new instance of the StringWriter class with the specified format control.

System_CAPS_pubmethodStringWriter(StringBuilder)

Initializes a new instance of the StringWriter class that writes to the specified StringBuilder.

System_CAPS_pubmethodStringWriter(StringBuilder, IFormatProvider)

Initializes a new instance of the StringWriter class that writes to the specified StringBuilder and has the specified format provider.

NameDescription
System_CAPS_pubpropertyEncoding

Gets the Encoding in which the output is written.(Overrides TextWriter.Encoding.)

System_CAPS_pubpropertyFormatProvider

Gets an object that controls formatting.(Inherited from TextWriter.)

System_CAPS_pubpropertyNewLine

Gets or sets the line terminator string used by the current TextWriter.(Inherited from TextWriter.)

NameDescription
System_CAPS_pubmethodClose()

Closes the current StringWriter and the underlying stream.(Overrides TextWriter.Close().)

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

Releases all resources used by the TextWriter object.(Inherited from TextWriter.)

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the StringWriter and optionally releases the managed resources.(Overrides TextWriter.Dispose(Boolean).)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodFlush()

Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.(Inherited from TextWriter.)

System_CAPS_pubmethodFlushAsync()

Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device. (Overrides TextWriter.FlushAsync().)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetStringBuilder()

Returns the underlying StringBuilder.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodToString()

Returns a string containing the characters written to the current StringWriter so far.(Overrides Object.ToString().)

System_CAPS_pubmethodWrite(Boolean)

Writes the text representation of a Boolean value to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Char)

Writes a character to the string.(Overrides TextWriter.Write(Char).)

System_CAPS_pubmethodWrite(Char[])

Writes a character array to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Char[], Int32, Int32)

Writes a subarray of characters to the string.(Overrides TextWriter.Write(Char[], Int32, Int32).)

System_CAPS_pubmethodWrite(Decimal)

Writes the text representation of a decimal value to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Double)

Writes the text representation of an 8-byte floating-point value to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Int32)

Writes the text representation of a 4-byte signed integer to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Int64)

Writes the text representation of an 8-byte signed integer to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Object)

Writes the text representation of an object to the text string or stream by calling the ToString method on that object.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(Single)

Writes the text representation of a 4-byte floating-point value to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(String)

Writes a string to the current string.(Overrides TextWriter.Write(String).)

System_CAPS_pubmethodWrite(String, Object)

Writes a formatted string to the text string or stream, using the same semantics as the String.Format(String, Object) method.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(String, Object, Object)

Writes a formatted string to the text string or stream, using the same semantics as the String.Format(String, Object, Object) method.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(String, Object, Object, Object)

Writes a formatted string to the text string or stream, using the same semantics as the String.Format(String, Object, Object, Object) method.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(String, Object[])

Writes a formatted string to the text string or stream, using the same semantics as the String.Format(String, Object[]) method.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(UInt32)

Writes the text representation of a 4-byte unsigned integer to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWrite(UInt64)

Writes the text representation of an 8-byte unsigned integer to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteAsync(Char)

Writes a character to the string asynchronously.(Overrides TextWriter.WriteAsync(Char).)

System_CAPS_pubmethodWriteAsync(Char[])

Writes a character array to the text string or stream asynchronously.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteAsync(Char[], Int32, Int32)

Writes a subarray of characters to the string asynchronously.(Overrides TextWriter.WriteAsync(Char[], Int32, Int32).)

System_CAPS_pubmethodWriteAsync(String)

Writes a string to the current string asynchronously.(Overrides TextWriter.WriteAsync(String).)

System_CAPS_pubmethodWriteLine()

Writes a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Boolean)

Writes the text representation of a Boolean value followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Char)

Writes a character followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Char[])

Writes an array of characters followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Char[], Int32, Int32)

Writes a subarray of characters followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Decimal)

Writes the text representation of a decimal value followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Double)

Writes the text representation of a 8-byte floating-point value followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Int32)

Writes the text representation of a 4-byte signed integer followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Int64)

Writes the text representation of an 8-byte signed integer followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Object)

Writes the text representation of an object by calling the ToString method on that object, followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(Single)

Writes the text representation of a 4-byte floating-point value followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(String)

Writes a string followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(String, Object)

Writes a formatted string and a new line to the text string or stream, using the same semantics as the String.Format(String, Object) method.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(String, Object, Object)

Writes a formatted string and a new line to the text string or stream, using the same semantics as the String.Format(String, Object, Object) method.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(String, Object, Object, Object)

Writes out a formatted string and a new line, using the same semantics as Format.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(String, Object[])

Writes out a formatted string and a new line, using the same semantics as Format.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(UInt32)

Writes the text representation of a 4-byte unsigned integer followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLine(UInt64)

Writes the text representation of an 8-byte unsigned integer followed by a line terminator to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLineAsync()

Writes a line terminator asynchronously to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLineAsync(Char)

Writes a character followed by a line terminator asynchronously to the string.(Overrides TextWriter.WriteLineAsync(Char).)

System_CAPS_pubmethodWriteLineAsync(Char[])

Writes an array of characters followed by a line terminator asynchronously to the text string or stream.(Inherited from TextWriter.)

System_CAPS_pubmethodWriteLineAsync(Char[], Int32, Int32)

Writes a subarray of characters followed by a line terminator asynchronously to the string.(Overrides TextWriter.WriteLineAsync(Char[], Int32, Int32).)

System_CAPS_pubmethodWriteLineAsync(String)

Writes a string followed by a line terminator asynchronously to the current string.(Overrides TextWriter.WriteLineAsync(String).)

NameDescription
System_CAPS_protfieldCoreNewLine

Stores the newline characters used for this TextWriter.(Inherited from TextWriter.)

StringWriter enables you to write to a string synchronously or asynchronously. You can write a character at a time with the Write(Char) or the WriteAsync(Char) method, a string at a time using the Write(String) or the WriteAsync(String) method. In addition, you can write a character, an array of characters or a string followed by the line terminator asynchronously with one of the WriteLineAsync methods.

System_CAPS_importantImportant

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try /catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

The following table lists examples of other typical or related I/O tasks.

To do this...

See the example in this topic...

Create a text file.

How to: Write Text to a File

Write to a text file.

How to: Write Text to a File

Read from a text file.

How to: Read Text from a File

Append text to a file.

How to: Open and Append to a Log File

File.AppendText

FileInfo.AppendText

Get the size of a file.

FileInfo.Length

Get the attributes of a file.

File.GetAttributes

Set the attributes of a file.

File.SetAttributes

Determine if a file exists.

File.Exists

Read from a binary file.

How to: Read and Write to a Newly Created Data File

Write to a binary file.

How to: Read and Write to a Newly Created Data File

The following code example demonstrates the creation of a continuous paragraph from a group of double-spaced sentences, and then the conversion of the paragraph back to the original text.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: