StringWriter Constructor ()
Initializes a new instance of the StringWriter class.
Assembly: mscorlib (in mscorlib.dll)
A new StringBuilder object is automatically created and associated with the new instance of the StringWriter class. 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 how to construct a string using the StringWriter class.
using namespace System; using namespace System::IO; using namespace System::Text; int main() { StringWriter^ strWriter = gcnew StringWriter; // Use the three overloads of the Write method that are // overridden by the StringWriter class. strWriter->Write( "file path characters are: " ); strWriter->Write( Path::InvalidPathChars, 0, Path::InvalidPathChars->Length ); strWriter->Write( Char::Parse( "." ) ); // Use the underlying StringBuilder for more complex // manipulations of the string. strWriter->GetStringBuilder()->Insert( 0, "Invalid " ); Console::WriteLine( "The following string is {0} encoded.\n{1}", strWriter->Encoding->EncodingName, 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