翻訳への提案を行います
 
他のユーザーによる提案:

progress indicator
他の提案はありません。
クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 4
System.Text 名前空間
System.Text
StringBuilder クラス
StringBuilder メソッド
AppendFormat メソッド
 AppendFormat メソッド (String, Object, ...
すべて縮小/すべて展開 すべて縮小
コンテンツの表示:   英語と日本語を並べて表示コンテンツの表示: 英語と日本語を並べて表示
.NET Framework Class Library
StringBuilder..::.AppendFormat Method (String, Object, Object, Object)

Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of either of three arguments.

Namespace:  System.Text
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
Public Function AppendFormat ( _
    format As String, _
    arg0 As Object, _
    arg1 As Object, _
    arg2 As Object _
) As StringBuilder
C#
public StringBuilder AppendFormat(
    string format,
    Object arg0,
    Object arg1,
    Object arg2
)
Visual C++
public:
StringBuilder^ AppendFormat(
    String^ format, 
    Object^ arg0, 
    Object^ arg1, 
    Object^ arg2
)
F#
member AppendFormat : 
        format:string * 
        arg0:Object * 
        arg1:Object * 
        arg2:Object -> StringBuilder 

Parameters

format
Type: System..::.String
A composite format string (see Remarks).
arg0
Type: System..::.Object
The first object to format.
arg1
Type: System..::.Object
The second object to format.
arg2
Type: System..::.Object
The third object to format.

Return Value

Type: System.Text..::.StringBuilder
A reference to this instance with format appended. Each format item in format is replaced by the string representation of the corresponding object argument.
ExceptionCondition
ArgumentNullException

format is nullNothingnullptra null reference (Nothing in Visual Basic).

FormatException

format is invalid.

-or-

The index of a format item is less than 0 (zero), or greater than or equal to 3.

ArgumentOutOfRangeException

The length of the expanded string would exceed MaxCapacity.

This method uses the composite formatting feature of the .NET Framework to convert the value of an object to its text representation and embed that representation in the current StringBuilder object.

The format parameter consists of zero or more runs of text intermixed with zero or more indexed placeholders, called format items, that correspond to arg0 through arg3, the objects in the parameter list of this method. The formatting process replaces each format item with the string representation of the corresponding object.

The syntax of a format item is as follows:

{index[,length][:formatString]}

Elements in square brackets are optional. The following table describes each element.

Element

Description

index

The zero-based position in the parameter list of the object to be formatted. If the object specified by index is nullNothingnullptra null reference (Nothing in Visual Basic), the format item is replaced by String..::.Empty. If there is no parameter in the index position, a FormatException is thrown.

,length

The minimum number of characters in the string representation of the parameter. If positive, the parameter is right-aligned; if negative, it is left-aligned.

:formatString

A standard or custom format string that is supported by the parameter.

NoteNote

For the standard and custom format strings used with date and time values, see Standard Date and Time Format Strings and Custom Date and Time Format Strings. For the standard and custom format strings used with numeric values, see Standard Numeric Format Strings and Custom Numeric Format Strings. For the standard format strings used with enumerations, see Enumeration Format Strings.

arg0, arg1, and arg2 represent the objects to be formatted. Each format item in format is replaced with the string representation of either arg0, arg1, or arg2, depending on the index of the format item. If the format item includes formatString and the corresponding object in args implements the IFormattable interface, then argx.ToString(formatString, null) defines the formatting, where x is the index of the argument. Otherwise, argx.ToString() defines the formatting.

If the string assigned to format is "Thank you for your purchase of {0:####} copies of Microsoft®.NET (Core Reference)." and arg0 is an Int16 with the value 123, the return value will be "Thank you for your purchase of 123 copies of Microsoft®.NET (Core Reference)."

If the string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg0 is an Int16 with the value 42, the return value (where underscores represent padding spaces) will be "Brad's dog has 42______ fleas."

The following example demonstrates the AppendFormat method.

Visual Basic
Imports System
Imports System.Text
Imports System.Globalization

Class Sample
   Private Shared sb As New StringBuilder()

   Public Shared Sub Main()
      Dim var1 As Integer = 111
      Dim var2 As Single = 2.22F
      Dim var3 As String = "abcd"
      Dim var4 As Object() =  {3, 4.4, "X"c}

      Console.WriteLine()
      Console.WriteLine("StringBuilder.AppendFormat method:")
      sb.AppendFormat("1) {0}", var1)
      Show(sb)
      sb.AppendFormat("2) {0}, {1}", var1, var2)
      Show(sb)
      sb.AppendFormat("3) {0}, {1}, {2}", var1, var2, var3)
      Show(sb)
      sb.AppendFormat("4) {0}, {1}, {2}", var4)
      Show(sb)
      Dim ci As New CultureInfo("es-ES", True)
      sb.AppendFormat(ci, "5) {0}", var2)
      Show(sb)
   End Sub 'Main

   Public Shared Sub Show(sbs As StringBuilder)
      Console.WriteLine(sbs.ToString())
      sb.Length = 0
   End Sub 'Show
End Class 'Sample
'
'This example produces the following results:
'
'StringBuilder.AppendFormat method:
'1) 111
'2) 111, 2.22
'3) 111, 2.22, abcd
'4) 3, 4.4, X
'5) 2,22
C#
using System;
using System.Text;
using System.Globalization;

class Sample 
{
    static StringBuilder sb = new StringBuilder();

    public static void Main() 
    {
    int    var1   = 111;
    float  var2   = 2.22F;
    string var3   = "abcd";
    object[] var4 = {3, 4.4, 'X'};

    Console.WriteLine();
    Console.WriteLine("StringBuilder.AppendFormat method:");
    sb.AppendFormat("1) {0}", var1);
    Show(sb);
    sb.AppendFormat("2) {0}, {1}", var1, var2);
    Show(sb);
    sb.AppendFormat("3) {0}, {1}, {2}", var1, var2, var3);
    Show(sb);
    sb.AppendFormat("4) {0}, {1}, {2}", var4);
    Show(sb);
    CultureInfo ci = new CultureInfo("es-ES", true);
    sb.AppendFormat(ci, "5) {0}", var2);
    Show(sb);
    }

    public static void Show(StringBuilder sbs)
    {
    Console.WriteLine(sbs.ToString());
    sb.Length = 0;
    }
}
/*
This example produces the following results:

StringBuilder.AppendFormat method:
1) 111
2) 111, 2.22
3) 111, 2.22, abcd
4) 3, 4.4, X
5) 2,22
*/
Visual C++
using namespace System;
using namespace System::Text;
using namespace System::Globalization;
void Show( StringBuilder^ sbs )
{
   Console::WriteLine( sbs );
   sbs->Length = 0;
}

int main()
{
   StringBuilder^ sb = gcnew StringBuilder;
   int var1 = 111;
   float var2 = 2.22F;
   String^ var3 = "abcd";
   array<Object^>^var4 = {3,4.4,(Char)'X'};
   Console::WriteLine();
   Console::WriteLine( "StringBuilder.AppendFormat method:" );
   sb->AppendFormat( "1) {0}", var1 );
   Show( sb );
   sb->AppendFormat( "2) {0}, {1}", var1, var2 );
   Show( sb );
   sb->AppendFormat( "3) {0}, {1}, {2}", var1, var2, var3 );
   Show( sb );
   sb->AppendFormat( "4) {0}, {1}, {2}", var4 );
   Show( sb );
   CultureInfo^ ci = gcnew CultureInfo( "es-ES",true );
   array<Object^>^temp1 = {var2};
   sb->AppendFormat( ci, "5) {0}", temp1 );
   Show( sb );
}

/*
This example produces the following results:

StringBuilder.AppendFormat method:
1) 111
2) 111, 2.22
3) 111, 2.22, abcd
4) 3, 4.4, X
5) 2,22
*/

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework クラス ライブラリ
StringBuilder..::.AppendFormat メソッド (String, Object, Object, Object)

0 個以上の書式指定項目を含む複合書式指定文字列を処理し、結果として返された文字列をこのインスタンスに追加します。 各書式指定項目は、3 つの引数のいずれかの文字列形式に置換されます。

名前空間:  System.Text
アセンブリ:  mscorlib (mscorlib.dll 内)
Visual Basic
Public Function AppendFormat ( _
    format As String, _
    arg0 As Object, _
    arg1 As Object, _
    arg2 As Object _
) As StringBuilder
C#
public StringBuilder AppendFormat(
    string format,
    Object arg0,
    Object arg1,
    Object arg2
)
Visual C++
public:
StringBuilder^ AppendFormat(
    String^ format, 
    Object^ arg0, 
    Object^ arg1, 
    Object^ arg2
)
F#
member AppendFormat : 
        format:string * 
        arg0:Object * 
        arg1:Object * 
        arg2:Object -> StringBuilder 

パラメーター

format
型: System..::.String
複合書式指定文字列 (「解説」を参照してください)。
arg0
型: System..::.Object
書式指定する第 1 オブジェクト。
arg1
型: System..::.Object
書式指定する第 2 オブジェクト。
arg2
型: System..::.Object
書式指定する第 3 オブジェクト。

戻り値

型: System.Text..::.StringBuilder
format が追加されたこのインスタンスへの参照。 format の各書式指定項目は、対応するオブジェクト引数の文字列形式に置換されます。
例外条件
ArgumentNullException

formatnullNothingnullptrnull 参照 (Visual Basic では Nothing) なので、

FormatException

format が無効です。

または

書式指定項目のインデックスが 0 (ゼロ) 未満または 3 以上です。

ArgumentOutOfRangeException

文字列を展開すると、長さが MaxCapacity を超えます。

このメソッドでは、.NET Framework の複合書式指定機能を使用して、オブジェクトの値を対応するテキスト表現に変換し、そのテキスト表現を現在の StringBuilder オブジェクト中に埋め込みます。

format パラメーターは、ゼロ個以上のテキストに、このメソッドのパラメーター リストに指定された arg0 から arg3 までのオブジェクトと対応する、ゼロ個以上のインデックス付きプレースホルダー (書式項目と呼ばれる) を組み合わせて指定します。 各書式項目は、書式設定プロセスで、対応するオブジェクトの文字列形式に置き換えられます。

書式項目の構文を次に示します。

{index[,length][:formatString]}

角かっこで囲まれている要素は省略可能です。 各要素について次の表で説明します。

要素

説明

index

書式設定するオブジェクトのパラメーター リスト内の 0 から始まる位置。 index で指定されたオブジェクトが nullNothingnullptrnull 参照 (Visual Basic では Nothing) の場合、書式項目は String..::.Empty で置き換えられます。 index 位置にパラメーターが存在しない場合、FormatException がスローされます。

,length

パラメーターの文字列形式の最小文字数。 正数の場合、パラメーターは右揃えになります。負数の場合、左揃えになります。

:formatString

パラメーターでサポートされている標準書式指定文字列またはカスタム書式指定文字列。

メモメモ

日付と時刻の値で使用する標準書式指定文字列およびカスタム書式指定文字列の詳細については、「標準の日付と時刻の書式指定文字列」および「カスタムの日付と時刻の書式指定文字列」を参照してください。 数値で使用する標準書式指定文字列およびカスタム書式指定文字列の詳細については、「標準の数値書式指定文字列」および「カスタム数値書式指定文字列」を参照してください。 列挙体で使用する標準書式指定文字列については、「列挙型書式指定文字列」を参照してください。

arg0arg1、および arg2 は、書式設定するオブジェクトを表します。 format の各書式指定項目は、書式指定項目のインデックスに応じて、arg0arg1 または arg2 の文字列形式に置換されます。 書式指定項目に formatString が含まれており、args の対応するオブジェクトが IFormattable インターフェイスを実装している場合、argx.ToString(formatString, null) によって書式が定義されます。ここで、x は引数のインデックスです。 それ以外の場合、argx.ToString() は書式設定を定義します。

format に代入された文字列が "Thank you for your purchase of {0:####} copies of Microsoft®.NET (Core Reference)." で arg0 が値 123 の Int16 である場合、戻り値は "Thank you for your purchase of 123 copies of Microsoft®.NET (Core Reference)." になります。

format に代入された文字列が "Brad's dog has {0,-8:G} fleas." で、arg0 が値 42 の Int16 の場合、戻り値は "Brad's dog has 42______ fleas." になります。この例のアンダースコアは埋め込まれたスペースを表します。

AppendFormat メソッドの例を次に示します。

Visual Basic
Imports System
Imports System.Text
Imports System.Globalization

Class Sample
   Private Shared sb As New StringBuilder()

   Public Shared Sub Main()
      Dim var1 As Integer = 111
      Dim var2 As Single = 2.22F
      Dim var3 As String = "abcd"
      Dim var4 As Object() =  {3, 4.4, "X"c}

      Console.WriteLine()
      Console.WriteLine("StringBuilder.AppendFormat method:")
      sb.AppendFormat("1) {0}", var1)
      Show(sb)
      sb.AppendFormat("2) {0}, {1}", var1, var2)
      Show(sb)
      sb.AppendFormat("3) {0}, {1}, {2}", var1, var2, var3)
      Show(sb)
      sb.AppendFormat("4) {0}, {1}, {2}", var4)
      Show(sb)
      Dim ci As New CultureInfo("es-ES", True)
      sb.AppendFormat(ci, "5) {0}", var2)
      Show(sb)
   End Sub 'Main

   Public Shared Sub Show(sbs As StringBuilder)
      Console.WriteLine(sbs.ToString())
      sb.Length = 0
   End Sub 'Show
End Class 'Sample
'
'This example produces the following results:
'
'StringBuilder.AppendFormat method:
'1) 111
'2) 111, 2.22
'3) 111, 2.22, abcd
'4) 3, 4.4, X
'5) 2,22
C#
using System;
using System.Text;
using System.Globalization;

class Sample 
{
    static StringBuilder sb = new StringBuilder();

    public static void Main() 
    {
    int    var1   = 111;
    float  var2   = 2.22F;
    string var3   = "abcd";
    object[] var4 = {3, 4.4, 'X'};

    Console.WriteLine();
    Console.WriteLine("StringBuilder.AppendFormat method:");
    sb.AppendFormat("1) {0}", var1);
    Show(sb);
    sb.AppendFormat("2) {0}, {1}", var1, var2);
    Show(sb);
    sb.AppendFormat("3) {0}, {1}, {2}", var1, var2, var3);
    Show(sb);
    sb.AppendFormat("4) {0}, {1}, {2}", var4);
    Show(sb);
    CultureInfo ci = new CultureInfo("es-ES", true);
    sb.AppendFormat(ci, "5) {0}", var2);
    Show(sb);
    }

    public static void Show(StringBuilder sbs)
    {
    Console.WriteLine(sbs.ToString());
    sb.Length = 0;
    }
}
/*
This example produces the following results:

StringBuilder.AppendFormat method:
1) 111
2) 111, 2.22
3) 111, 2.22, abcd
4) 3, 4.4, X
5) 2,22
*/
Visual C++
using namespace System;
using namespace System::Text;
using namespace System::Globalization;
void Show( StringBuilder^ sbs )
{
   Console::WriteLine( sbs );
   sbs->Length = 0;
}

int main()
{
   StringBuilder^ sb = gcnew StringBuilder;
   int var1 = 111;
   float var2 = 2.22F;
   String^ var3 = "abcd";
   array<Object^>^var4 = {3,4.4,(Char)'X'};
   Console::WriteLine();
   Console::WriteLine( "StringBuilder.AppendFormat method:" );
   sb->AppendFormat( "1) {0}", var1 );
   Show( sb );
   sb->AppendFormat( "2) {0}, {1}", var1, var2 );
   Show( sb );
   sb->AppendFormat( "3) {0}, {1}, {2}", var1, var2, var3 );
   Show( sb );
   sb->AppendFormat( "4) {0}, {1}, {2}", var4 );
   Show( sb );
   CultureInfo^ ci = gcnew CultureInfo( "es-ES",true );
   array<Object^>^temp1 = {var2};
   sb->AppendFormat( ci, "5) {0}", temp1 );
   Show( sb );
}

/*
This example produces the following results:

StringBuilder.AppendFormat method:
1) 111
2) 111, 2.22
3) 111, 2.22, abcd
4) 3, 4.4, X
5) 2,22
*/

.NET Framework

サポート対象: 4、3.5、3.0、2.0、1.1、1.0

.NET Framework Client Profile

サポート対象: 4、3.5 SP1

Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2

.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2012 Microsoft. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker