次の方法で共有


StringWriter コンストラクタ ()

StringWriter クラスの新しいインスタンスを初期化します。

名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)

構文

'宣言
Public Sub New
'使用
Dim instance As New StringWriter
public StringWriter ()
public:
StringWriter ()
public StringWriter ()
public function StringWriter ()

解説

新しい StringBuilder が自動的に作成され、新しい StringWriter と関連付けられます。

その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。

実行するタスク

参考例があるトピック

テキスト ファイルを作成する。

方法 : ファイルにテキストを書き込む

テキスト ファイルに書き込む。

方法 : ファイルにテキストを書き込む

テキスト ファイルから読み取る。

方法 : ファイルからテキストを読み取る

テキストをファイルに追加する。

方法 : ログ ファイルを開いて情報を追加する

File.AppendText

FileInfo.AppendText

ファイルのサイズを取得する。

FileInfo.Length

ファイルの属性を取得する。

File.GetAttributes

ファイルの属性を設定する。

File.SetAttributes

ファイルが存在するかどうかを判別する。

File.Exists

バイナリ ファイルから読み取る。

方法 : 新しく作成されたデータ ファイルに対して読み書きする

バイナリ ファイルに書き込む。

方法 : 新しく作成されたデータ ファイルに対して読み書きする

使用例

次に示すのは、StringWriter クラスを使用して文字列を構築するコード例です。

Imports Microsoft.VisualBasic
Imports System
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
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());
    }
}
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() );
   
}
import System.*;
import System.IO.*;
import System.Text.*;

class StrWriter
{
    public static void main(String[] args)
    {
        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.get_Encoding().get_EncodingName(), strWriter.ToString());
    } //main
} //StrWriter

プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

.NET Compact Framework

サポート対象 : 2.0、1.0

参照

関連項目

StringWriter クラス
StringWriter メンバ
System.IO 名前空間

その他の技術情報

ファイルおよびストリーム入出力
方法 : ファイルからテキストを読み取る
方法 : ファイルにテキストを書き込む