StringWriter Konstruktory

Definice

Inicializuje novou instanci StringWriter třídy.

Přetížení

StringWriter()

Inicializuje novou instanci StringWriter třídy .

StringWriter(IFormatProvider)

Inicializuje novou instanci StringWriter třídy se zadaným formátem ovládacího prvku.

StringWriter(StringBuilder)

Inicializuje novou instanci StringWriter třídy , která zapisuje do zadaného StringBuilderobjektu .

StringWriter(StringBuilder, IFormatProvider)

Inicializuje novou instanci StringWriter třídy, která zapisuje do zadaného StringBuilder a má zadaného zprostředkovatele formátu.

StringWriter()

Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs

Inicializuje novou instanci StringWriter třídy .

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

Příklady

Následující příklad kódu ukazuje, jak vytvořit řetězec pomocí StringWriter třídy .

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

Poznámky

Nový StringBuilder objekt se automaticky vytvoří a přidružuje StringWriter k nové instanci třídy . Vzhledem k tomu, že pro tento konstruktor není zadán ovládací prvek formátu, bude nová instance inicializována pomocí CultureInfo.CurrentCulture.

Následující tabulka uvádí příklady dalších typických nebo souvisejících vstupně-výstupních úloh.

Požadovaná akce... Další informace naleznete v příkladu v tomto tématu...
Create textový soubor. Postupy: Zápis textu do souboru
Zápis do textového souboru Postupy: Zápis textu do souboru
Čtení z textového souboru Postupy: Čtení textu ze souboru
Připojení textu k souboru Postupy: Otevření a připojení k souboru protokolu

File.AppendText

FileInfo.AppendText
Získejte velikost souboru. FileInfo.Length
Získá atributy souboru. File.GetAttributes
Nastavte atributy souboru. File.SetAttributes
Zjistěte, jestli existuje soubor. File.Exists
Čtení z binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru
Zápis do binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru

Viz také

Platí pro

StringWriter(IFormatProvider)

Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs

Inicializuje novou instanci StringWriter třídy se zadaným formátem ovládacího prvku.

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)

Parametry

formatProvider
IFormatProvider

Objekt IFormatProvider , který řídí formátování.

Příklady

Následující příklad kódu ukazuje, jak vytvořit řetězec v konkrétní jazykové verzi.

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

Poznámky

Nový StringBuilder objekt se automaticky vytvoří a přidružuje StringWriter k nové instanci třídy .

Následující tabulka uvádí příklady dalších typických nebo souvisejících vstupně-výstupních úloh.

Požadovaná akce... Další informace naleznete v příkladu v tomto tématu...
Create textový soubor. Postupy: Zápis textu do souboru
Zápis do textového souboru Postupy: Zápis textu do souboru
Čtení z textového souboru Postupy: Čtení textu ze souboru
Připojení textu k souboru Postupy: Otevření a připojení k souboru protokolu

File.AppendText

FileInfo.AppendText
Získejte velikost souboru. FileInfo.Length
Získá atributy souboru. File.GetAttributes
Nastavte atributy souboru. File.SetAttributes
Zjistěte, jestli existuje soubor. File.Exists
Čtení z binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru
Zápis do binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru

Viz také

Platí pro

StringWriter(StringBuilder)

Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs

Inicializuje novou instanci StringWriter třídy , která zapisuje do zadaného StringBuilderobjektu .

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)

Parametry

sb
StringBuilder

Objekt StringBuilder , do který chcete zapisovat.

Výjimky

sb je null.

Příklady

Následující příklad kódu ukazuje použití StringBuilder třídy k úpravě podkladového řetězce v uzavřeném StringWriterobjektu .

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

Poznámky

Vzhledem k tomu, že pro tento konstruktor není zadán ovládací prvek formátu, bude nová instance inicializována pomocí CultureInfo.CurrentCulture.

Následující tabulka uvádí příklady dalších typických nebo souvisejících vstupně-výstupních úloh.

Požadovaná akce... Další informace naleznete v příkladu v tomto tématu...
Create textový soubor. Postupy: Zápis textu do souboru
Zápis do textového souboru Postupy: Zápis textu do souboru
Čtení z textového souboru Postupy: Čtení textu ze souboru
Připojení textu k souboru Postupy: Otevření a připojení k souboru protokolu

File.AppendText

FileInfo.AppendText
Získejte velikost souboru. FileInfo.Length
Získá atributy souboru. File.GetAttributes
Nastavte atributy souboru. File.SetAttributes
Zjistěte, jestli existuje soubor. File.Exists
Čtení z binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru
Zápis do binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru

Viz také

Platí pro

StringWriter(StringBuilder, IFormatProvider)

Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs
Zdroj:
StringWriter.cs

Inicializuje novou instanci StringWriter třídy, která zapisuje do zadaného StringBuilder a má zadaného zprostředkovatele formátu.

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)

Parametry

sb
StringBuilder

Objekt StringBuilder , do který chcete zapisovat.

formatProvider
IFormatProvider

Objekt IFormatProvider , který řídí formátování.

Výjimky

sb je null.

Poznámky

Následující tabulka uvádí příklady dalších typických nebo souvisejících vstupně-výstupních úloh.

Požadovaná akce... Další informace naleznete v příkladu v tomto tématu...
Create textový soubor. Postupy: Zápis textu do souboru
Zápis do textového souboru Postupy: Zápis textu do souboru
Čtení z textového souboru. Postupy: Čtení textu ze souboru
Připojení textu k souboru Postupy: Otevření a připojení k souboru protokolu

File.AppendText

FileInfo.AppendText
Získejte velikost souboru. FileInfo.Length
Získejte atributy souboru. File.GetAttributes
Nastavte atributy souboru. File.SetAttributes
Zjistěte, jestli soubor existuje. File.Exists
Čtení z binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru
Zápis do binárního souboru Postupy: Čtení a zápis do nově vytvořeného datového souboru

Viz také

Platí pro