StringWriter Constructor (StringBuilder^)
Initializes a new instance of the StringWriter class that writes to the specified StringBuilder.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- sb
-
Type:
System.Text::StringBuilder^
The StringBuilder object to write to.
| Exception | Condition |
|---|---|
| ArgumentNullException | sb is null. |
Since a format control is not specified for this constructor, the new instance will be initialized with CultureInfo::CurrentCulture.
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. | |
Write to a text file. | |
Read from a text file. | |
Append text to a file. | |
Get the size of a file. | |
Get the attributes of a file. | |
Set the attributes of a file. | |
Determine if a file exists. | |
Read from a binary file. | |
Write to a binary file. |
The following code example demonstrates using the StringBuilder class to modify the underlying string in a closed StringWriter.
using namespace System; using namespace System::IO; using namespace System::Text; int main() { StringBuilder^ strBuilder = gcnew StringBuilder( "file path characters are: " ); StringWriter^ strWriter = gcnew StringWriter( strBuilder ); strWriter->Write( Path::InvalidPathChars, 0, Path::InvalidPathChars->Length ); strWriter->Close(); // Since the StringWriter is closed, an exception will // be thrown if the Write method is called. However, // the StringBuilder can still manipulate the string. strBuilder->Insert( 0, "Invalid " ); Console::WriteLine( strWriter->ToString() ); }
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