指定した StringBuilder への書き込みを行う StringWriter クラスの新しいインスタンスを初期化します。
名前空間: System.IO
アセンブリ: mscorlib (mscorlib.dll 内)
構文
'宣言
Public Sub New ( _
sb As StringBuilder _
)
'使用
Dim sb As StringBuilder
Dim instance As New StringWriter(sb)
public StringWriter (
StringBuilder sb
)
public:
StringWriter (
StringBuilder^ sb
)
public StringWriter (
StringBuilder sb
)
public function StringWriter (
sb : StringBuilder
)
パラメータ
- sb
書き込む StringBuilder。
例外
| 例外の種類 | 条件 |
|---|---|
sb が null 参照 (Visual Basic では Nothing) です。 |
解説
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
実行するタスク |
参考例があるトピック |
|---|---|
テキスト ファイルを作成する。 |
|
テキスト ファイルに書き込む。 |
|
テキスト ファイルから読み取る。 |
|
テキストをファイルに追加する。 |
|
ファイルのサイズを取得する。 |
|
ファイルの属性を取得する。 |
|
ファイルの属性を設定する。 |
|
ファイルが存在するかどうかを判別する。 |
|
バイナリ ファイルから読み取る。 |
|
バイナリ ファイルに書き込む。 |
使用例
次に示すのは、StringBuilder クラスを使用して、閉じられた StringWriter の基になる文字列を変更するコード例です。
Imports System
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
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());
}
}
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() );
}
import System.*;
import System.IO.*;
import System.Text.*;
class StrWriter
{
public static void main(String[] args)
{
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());
} //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 名前空間