StringWriter Constructores

Definición

Inicializa una nueva instancia de la clase StringWriter.

Sobrecargas

StringWriter()

Inicializa una nueva instancia de la clase StringWriter.

StringWriter(IFormatProvider)

Inicializa una nueva instancia de la clase StringWriter con el control de formato especificado.

StringWriter(StringBuilder)

Inicializa una nueva instancia de la clase StringWriter que escribe en el elemento StringBuilder especificado.

StringWriter(StringBuilder, IFormatProvider)

Inicializa una nueva instancia de la clase StringWriter que escribe en el StringBuilder especificado y tiene el proveedor de formato especificado.

StringWriter()

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

Inicializa una nueva instancia de la clase StringWriter.

public:
 StringWriter();
public StringWriter ();
Public Sub New ()

Ejemplos

En el ejemplo de código siguiente se muestra cómo construir una cadena mediante la StringWriter clase .

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() );
   
}
using System;
using System.IO;
using System.Text;

class StrWriter
{
    static void Main()
    {
        StringWriter strWriter  = new 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('.');

        // 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());
    }
}
Imports System.IO
Imports System.Text

Public Class StrWriter

    Shared Sub Main()

        Dim strWriter As StringWriter = new 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("."C)

        ' Use the underlying StringBuilder for more complex 
        ' manipulations of the string.
        strWriter.GetStringBuilder().Insert(0, "Invalid ")

        Console.WriteLine("The following string is {0} encoded." _
            & vbCrLf & "{1}", _
            strWriter.Encoding.EncodingName, strWriter.ToString())

    End Sub
End Class

Comentarios

Se crea automáticamente un nuevo StringBuilder objeto y se asocia a la nueva instancia de la StringWriter clase . Dado que no se especifica un control de formato para este constructor, la nueva instancia se inicializará con CultureInfo.CurrentCulture.

En la tabla siguiente se enumeran ejemplos de otras tareas de E/S típicas o relacionadas.

Para... Vea el ejemplo de este tema...
Crear un archivo de texto Cómo: Escribir texto en un archivo
Escribir en un archivo de texto. Cómo: Escribir texto en un archivo
Leer desde un archivo de texto. Cómo: Leer texto de un archivo
Anexe texto a un archivo. Cómo: Abrir y anexar a un archivo de registro

File.AppendText

FileInfo.AppendText
Obtiene el tamaño de un archivo. FileInfo.Length
Obtiene los atributos de un archivo. File.GetAttributes
Establezca los atributos de un archivo. File.SetAttributes
Determine si existe un archivo. File.Exists
Leer desde un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado
Escribir en un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado

Consulte también

Se aplica a

StringWriter(IFormatProvider)

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

Inicializa una nueva instancia de la clase StringWriter con el control de formato especificado.

public:
 StringWriter(IFormatProvider ^ formatProvider);
public StringWriter (IFormatProvider formatProvider);
public StringWriter (IFormatProvider? formatProvider);
new System.IO.StringWriter : IFormatProvider -> System.IO.StringWriter
Public Sub New (formatProvider As IFormatProvider)

Parámetros

formatProvider
IFormatProvider

Objeto IFormatProvider que controla las operaciones de formato.

Ejemplos

En el ejemplo de código siguiente se muestra cómo construir una cadena en una referencia cultural específica.

using namespace System;
using namespace System::Globalization;
using namespace System::IO;
int main()
{
   StringWriter^ strWriter = gcnew StringWriter( gcnew CultureInfo(  "ar-DZ" ) );
   strWriter->Write( DateTime::Now );
   
   Console::WriteLine( "Current date and time using the invariant culture: {0}\n"
   "Current date and time using the Algerian culture: {1}", DateTime::Now.ToString(), strWriter->ToString() );
   
}
using System;
using System.Globalization;
using System.IO;

class StrWriter
{
    static void Main()
    {
        StringWriter strWriter =
            new StringWriter(new CultureInfo("ar-DZ"));

        strWriter.Write(DateTime.Now);

        Console.WriteLine(
            "Current date and time using the invariant culture: {0}\n" +
            "Current date and time using the Algerian culture: {1}",
            DateTime.Now.ToString(), strWriter.ToString());
    }
}
Imports System.Globalization
Imports System.IO

Public Class StrWriter

    Shared Sub Main()
        Dim strWriter As New StringWriter(New CultureInfo("ar-DZ"))

        strWriter.Write(DateTime.Now)

        Console.WriteLine( _
            "Current date and time using the invariant culture: {0}" _
            & vbCrLf & _
            "Current date and time using the Algerian culture: {1}", _
            DateTime.Now.ToString(), strWriter.ToString())
    End Sub

End Class

Comentarios

Se crea automáticamente un nuevo StringBuilder objeto y se asocia a la nueva instancia de la StringWriter clase .

En la tabla siguiente se enumeran ejemplos de otras tareas de E/S típicas o relacionadas.

Para... Vea el ejemplo de este tema...
Crear un archivo de texto Cómo: Escribir texto en un archivo
Escribir en un archivo de texto. Cómo: Escribir texto en un archivo
Leer desde un archivo de texto. Cómo: Leer texto de un archivo
Anexe texto a un archivo. Cómo: Abrir y anexar a un archivo de registro

File.AppendText

FileInfo.AppendText
Obtiene el tamaño de un archivo. FileInfo.Length
Obtiene los atributos de un archivo. File.GetAttributes
Establezca los atributos de un archivo. File.SetAttributes
Determine si existe un archivo. File.Exists
Leer desde un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado
Escribir en un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado

Consulte también

Se aplica a

StringWriter(StringBuilder)

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

Inicializa una nueva instancia de la clase StringWriter que escribe en el elemento StringBuilder especificado.

public:
 StringWriter(System::Text::StringBuilder ^ sb);
public StringWriter (System.Text.StringBuilder sb);
new System.IO.StringWriter : System.Text.StringBuilder -> System.IO.StringWriter
Public Sub New (sb As StringBuilder)

Parámetros

sb
StringBuilder

Objeto StringBuilder en el que se va a escribir.

Excepciones

sb es null.

Ejemplos

En el ejemplo de código siguiente se muestra el uso de la StringBuilder clase para modificar la cadena subyacente en un objeto cerrado 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() );
   
}
using System;
using System.IO;
using System.Text;

class StrWriter
{
    static void Main()
    {
        StringBuilder strBuilder =
            new StringBuilder("file path characters are: ");
        StringWriter strWriter = new 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());
    }
}
Imports System.IO
Imports System.Text

Public Class StrWriter

    Shared Sub Main()
        Dim strBuilder As New StringBuilder( _
            "file path characters are: ")
        Dim strWriter As New 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())
    End Sub

End Class

Comentarios

Dado que no se especifica un control de formato para este constructor, la nueva instancia se inicializará con CultureInfo.CurrentCulture.

En la tabla siguiente se enumeran ejemplos de otras tareas de E/S típicas o relacionadas.

Para... Vea el ejemplo de este tema...
Crear un archivo de texto Cómo: Escribir texto en un archivo
Escribir en un archivo de texto. Cómo: Escribir texto en un archivo
Leer desde un archivo de texto. Cómo: Leer texto de un archivo
Anexe texto a un archivo. Cómo: Abrir y anexar a un archivo de registro

File.AppendText

FileInfo.AppendText
Obtiene el tamaño de un archivo. FileInfo.Length
Obtiene los atributos de un archivo. File.GetAttributes
Establezca los atributos de un archivo. File.SetAttributes
Determine si existe un archivo. File.Exists
Leer desde un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado
Escribir en un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado

Consulte también

Se aplica a

StringWriter(StringBuilder, IFormatProvider)

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

Inicializa una nueva instancia de la clase StringWriter que escribe en el StringBuilder especificado y tiene el proveedor de formato especificado.

public:
 StringWriter(System::Text::StringBuilder ^ sb, IFormatProvider ^ formatProvider);
public StringWriter (System.Text.StringBuilder sb, IFormatProvider formatProvider);
public StringWriter (System.Text.StringBuilder sb, IFormatProvider? formatProvider);
new System.IO.StringWriter : System.Text.StringBuilder * IFormatProvider -> System.IO.StringWriter
Public Sub New (sb As StringBuilder, formatProvider As IFormatProvider)

Parámetros

sb
StringBuilder

Objeto StringBuilder en el que se va a escribir.

formatProvider
IFormatProvider

Objeto IFormatProvider que controla las operaciones de formato.

Excepciones

sb es null.

Comentarios

En la tabla siguiente se enumeran ejemplos de otras tareas de E/S típicas o relacionadas.

Para... Vea el ejemplo de este tema...
Crear un archivo de texto Cómo: Escribir texto en un archivo
Escribir en un archivo de texto. Cómo: Escribir texto en un archivo
Leer desde un archivo de texto. Cómo: Leer texto de un archivo
Anexe texto a un archivo. Cómo: Abrir y anexar a un archivo de registro

File.AppendText

FileInfo.AppendText
Obtiene el tamaño de un archivo. FileInfo.Length
Obtiene los atributos de un archivo. File.GetAttributes
Establezca los atributos de un archivo. File.SetAttributes
Determine si existe un archivo. File.Exists
Leer desde un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado
Escribir en un archivo binario. Cómo: Leer y escribir en un archivo de datos recién creado

Consulte también

Se aplica a