Edit

Share via


StringWriter.Write Method

Definition

Writes data to the string.

Overloads

Write(Char[], Int32, Int32)

Writes a subarray of characters to the string.

Write(String)

Writes a string to the current string.

Write(StringBuilder)

Writes the string representation of a string builder to the current string.

Write(Char)

Writes a character to the string.

Write(ReadOnlySpan<Char>)

Writes the string representation of a span of chars to the current string.

Write(Char[], Int32, Int32)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Writes a subarray of characters to the string.

public:
 override void Write(cli::array <char> ^ buffer, int index, int count);
public override void Write (char[] buffer, int index, int count);
override this.Write : char[] * int * int -> unit
Public Overrides Sub Write (buffer As Char(), index As Integer, count As Integer)

Parameters

buffer
Char[]

The character array to write data from.

index
Int32

The position in the buffer at which to start reading data.

count
Int32

The maximum number of characters to write.

Exceptions

buffer is null.

index or count is negative.

(index + count)> buffer. Length.

The writer is closed.

Examples

This code example is part of a larger example provided for the StringWriter() constructor.

// 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 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('.');
' 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("."C)

Remarks

This method overrides TextWriter.Write.

This method writes count characters of data to this StringWriter from buffer, starting at position index.

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

See also

Applies to

Write(String)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Writes a string to the current string.

public:
 override void Write(System::String ^ value);
public override void Write (string value);
public override void Write (string? value);
override this.Write : string -> unit
Public Overrides Sub Write (value As String)

Parameters

value
String

The string to write.

Exceptions

The writer is closed.

Examples

This code example is part of a larger example provided for the StringWriter class.

convertedCharacter = Convert::ToChar( intCharacter );
if ( convertedCharacter == '.' )
{
   strWriter->Write(  ".\n\n" );
   
   // Bypass the spaces between sentences.
   strReader->Read();
   strReader->Read();
}
convertedCharacter = (char)intCharacter;
if(convertedCharacter == '.')
{
    strWriter.Write(".\n\n");

    // Bypass the spaces between sentences.
    strReader.Read();
    strReader.Read();
}
convertedCharacter = Convert.ToChar(intCharacter)
If convertedCharacter = "."C Then
    strWriter.Write("." & vbCrLf & vbCrLf)

    ' Bypass the spaces between sentences.
    strReader.Read()
    strReader.Read()

Remarks

This method overrides TextWriter.Write.

If the specified string is null, nothing is written.

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

See also

Applies to

Write(StringBuilder)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Writes the string representation of a string builder to the current string.

public:
 override void Write(System::Text::StringBuilder ^ value);
public override void Write (System.Text.StringBuilder? value);
override this.Write : System.Text.StringBuilder -> unit
Public Overrides Sub Write (value As StringBuilder)

Parameters

value
StringBuilder

The string builder to write to the string.

Applies to

Write(Char)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Writes a character to the string.

public:
 override void Write(char value);
public override void Write (char value);
override this.Write : char -> unit
Public Overrides Sub Write (value As Char)

Parameters

value
Char

The character to write.

Exceptions

The writer is closed.

Examples

This code example is part of a larger example provided for the StringWriter() constructor.

// 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 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('.');
' 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("."C)

Remarks

This method overrides TextWriter.Write.

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

See also

Applies to

Write(ReadOnlySpan<Char>)

Source:
StringWriter.cs
Source:
StringWriter.cs
Source:
StringWriter.cs

Writes the string representation of a span of chars to the current string.

public:
 override void Write(ReadOnlySpan<char> buffer);
public override void Write (ReadOnlySpan<char> buffer);
override this.Write : ReadOnlySpan<char> -> unit
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Char))

Parameters

buffer
ReadOnlySpan<Char>

A span of chars to write to the string.

Applies to