StringBuilder.Insert メソッド

指定したオブジェクトの文字列形式をこのインスタンスの指定した文字位置に挿入します。

オーバーロードの一覧

Boolean 値の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Boolean) As StringBuilder

[C#] public StringBuilder Insert(int, bool);

[C++] public: StringBuilder* Insert(int, bool);

[JScript] public function Insert(int, Boolean) : StringBuilder;

指定した 8 ビット符号なし整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Byte) As StringBuilder

[C#] public StringBuilder Insert(int, byte);

[C++] public: StringBuilder* Insert(int, unsigned char);

[JScript] public function Insert(int, Byte) : StringBuilder;

指定した Unicode 文字の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Char) As StringBuilder

[C#] public StringBuilder Insert(int, char);

[C++] public: StringBuilder* Insert(int, __wchar_t);

[JScript] public function Insert(int, Char) : StringBuilder;

指定した Unicode 文字の配列の文字列形式をこのインスタンスの指定した文字位置に挿入します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function Insert(Integer, Char()) As StringBuilder

[C#] public StringBuilder Insert(int, char[]);

[C++] public: StringBuilder* Insert(int, __wchar_t __gc[]);

[JScript] public function Insert(int, Char[]) : StringBuilder;

10 進数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Decimal) As StringBuilder

[C#] public StringBuilder Insert(int, decimal);

[C++] public: StringBuilder* Insert(int, Decimal);

[JScript] public function Insert(int, Decimal) : StringBuilder;

倍精度浮動小数点数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Double) As StringBuilder

[C#] public StringBuilder Insert(int, double);

[C++] public: StringBuilder* Insert(int, double);

[JScript] public function Insert(int, double) : StringBuilder;

指定した 16 ビット符号付き整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Short) As StringBuilder

[C#] public StringBuilder Insert(int, short);

[C++] public: StringBuilder* Insert(int, short);

[JScript] public function Insert(int, Int16) : StringBuilder;

指定した 32 ビット符号付き整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Integer) As StringBuilder

[C#] public StringBuilder Insert(int, int);

[C++] public: StringBuilder* Insert(int, int);

[JScript] public function Insert(int, int) : StringBuilder;

64 ビット符号付き整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Long) As StringBuilder

[C#] public StringBuilder Insert(int, long);

[C++] public: StringBuilder* Insert(int, __int64);

[JScript] public function Insert(int, long) : StringBuilder;

オブジェクトの文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Object) As StringBuilder

[C#] public StringBuilder Insert(int, object);

[C++] public: StringBuilder* Insert(int, Object*);

[JScript] public function Insert(int, Object) : StringBuilder;

指定した 8 ビット符号付き整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。このメソッドは、CLS と互換性がありません。

[Visual Basic] Overloads Public Function Insert(Integer, SByte) As StringBuilder

[C#] public StringBuilder Insert(int, sbyte);

[C++] public: StringBuilder* Insert(int, char);

[JScript] public function Insert(int, SByte) : StringBuilder;

単精度浮動小数点数の文字列形式をこのインスタンスの指定した文字位置に挿入します。

[Visual Basic] Overloads Public Function Insert(Integer, Single) As StringBuilder

[C#] public StringBuilder Insert(int, float);

[C++] public: StringBuilder* Insert(int, float);

[JScript] public function Insert(int, float) : StringBuilder;

文字列をこのインスタンスの指定した文字位置に挿入します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function Insert(Integer, String) As StringBuilder

[C#] public StringBuilder Insert(int, string);

[C++] public: StringBuilder* Insert(int, String*);

[JScript] public function Insert(int, String) : StringBuilder;

16 ビット符号なし整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。このメソッドは、CLS と互換性がありません。

[Visual Basic] Overloads Public Function Insert(Integer, UInt16) As StringBuilder

[C#] public StringBuilder Insert(int, ushort);

[C++] public: StringBuilder* Insert(int, unsigned short);

[JScript] public function Insert(int, UInt16) : StringBuilder;

32 ビット符号なし整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。このメソッドは、CLS と互換性がありません。

[Visual Basic] Overloads Public Function Insert(Integer, UInt32) As StringBuilder

[C#] public StringBuilder Insert(int, uint);

[C++] public: StringBuilder* Insert(int, unsigned int);

[JScript] public function Insert(int, UInt32) : StringBuilder;

64 ビット符号なし整数の文字列形式をこのインスタンスの指定した文字位置に挿入します。このメソッドは、CLS と互換性がありません。

[Visual Basic] Overloads Public Function Insert(Integer, UInt64) As StringBuilder

[C#] public StringBuilder Insert(int, ulong);

[C++] public: StringBuilder* Insert(int, unsigned __int64);

[JScript] public function Insert(int, UInt64) : StringBuilder;

指定した文字列の 1 つ以上のコピーをこのインスタンスの指定した文字位置に挿入します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function Insert(Integer, String, Integer) As StringBuilder

[C#] public StringBuilder Insert(int, string, int);

[C++] public: StringBuilder* Insert(int, String*, int);

[JScript] public function Insert(int, String, int) : StringBuilder;

Unicode 文字の指定した部分配列の文字列形式をこのインスタンスの指定した文字位置に挿入します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function Insert(Integer, Char(), Integer, Integer) As StringBuilder

[C#] public StringBuilder Insert(int, char[], int, int);

[C++] public: StringBuilder* Insert(int, __wchar_t __gc[], int, int);

[JScript] public function Insert(int, Char[], int, int) : StringBuilder;

使用例

[Visual Basic, C#, C++] メモ   ここでは、Insert のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
' This example demonstrates StringBuilder.Insert()
Imports System
Imports System.Text

Class Sample
   '                                 index: 012345
   Private Shared initialValue As String = "--[]--"
   Private Shared sb As StringBuilder
   
   Public Shared Sub Main()
      Dim xyz As String = "xyz"
      Dim abc As Char() =  {"a"c, "b"c, "c"c}
      Dim star As Char = "*"c
      Dim obj As [Object] = 0
      
      Dim xBool As Boolean = True
      Dim xByte As Byte = 1
      Dim xInt16 As Short = 2
      Dim xInt32 As Integer = 3
      Dim xInt64 As Long = 4
      Dim xDecimal As [Decimal] = 5
      Dim xSingle As Single = 6.6F
      Dim xDouble As Double = 7.7
      
      ' The following types are not CLS-compliant.
      ' Dim xUInt16 As System.UInt16 = 8 
      ' Dim xUInt32 As System.UInt32 = 9
      ' Dim xUInt64 As System.UInt64 = 10 
      ' Dim xSByte As System.SByte = - 11
      '
      Console.WriteLine("StringBuilder.Insert method")
      sb = New StringBuilder(initialValue)
      
      sb.Insert(3, xyz, 2)
      Show(1, sb)
      
      sb.Insert(3, xyz)
      Show(2, sb)
      
      sb.Insert(3, star)
      Show(3, sb)
      
      sb.Insert(3, abc)
      Show(4, sb)
      
      sb.Insert(3, abc, 1, 2)
      Show(5, sb)
      
      sb.Insert(3, xBool)     ' True
      Show(6, sb)
      
      sb.Insert(3, obj)       ' 0
      Show(7, sb)
      
      sb.Insert(3, xByte)     ' 1
      Show(8, sb)
      
      sb.Insert(3, xInt16)    ' 2
      Show(9, sb)
      
      sb.Insert(3, xInt32)    ' 3
      Show(10, sb)
      
      sb.Insert(3, xInt64)    ' 4
      Show(11, sb)
      
      sb.Insert(3, xDecimal)  ' 5
      Show(12, sb)
      
      sb.Insert(3, xSingle)   ' 6.6
      Show(13, sb)
      
      sb.Insert(3, xDouble)   ' 7.7
      Show(14, sb)
      
      ' The following Insert methods are not CLS-compliant.
      ' sb.Insert(3, xUInt16) ' 8
      ' sb.Insert(3, xUInt32) ' 9
      ' sb.Insert(3, xUInt64) ' 10
      ' sb.Insert(3, xSByte)  ' -11

   End Sub 'Main
   
   Public Shared Sub Show(overloadNumber As Integer, sbs As StringBuilder)
      Console.WriteLine("{0,2:G} = {1}", overloadNumber, sbs.ToString())
      sb = New StringBuilder(initialValue)
   End Sub 'Show
End Class 'Sample
'
'This example produces the following results:
'
'StringBuilder.Insert method
' 1 = --[xyzxyz]--
' 2 = --[xyz]--
' 3 = --[*]--
' 4 = --[abc]--
' 5 = --[bc]--
' 6 = --[True]--
' 7 = --[0]--
' 8 = --[1]--
' 9 = --[2]--
'10 = --[3]--
'11 = --[4]--
'12 = --[5]--
'13 = --[6.6]--
'14 = --[7.7]--
'

[C#] 
// This example demonstrates StringBuilder.Insert()
using System;
using System.Text;

class Sample 
{
//                         index: 012345
    static string initialValue = "--[]--";
    static StringBuilder sb;

    public static void Main() 
    {
    string      xyz       = "xyz";
    char[]      abc       = {'a', 'b', 'c'};
    char        star      = '*';
    Object     obj       = 0;

    bool        xBool     = true;
    byte        xByte     = 1;
    short       xInt16    = 2;
    int         xInt32    = 3;
    long        xInt64    = 4;
    Decimal     xDecimal  = 5;
    float       xSingle   = 6.6F;
    double      xDouble   = 7.7;

// The following types are not CLS-compliant.
    ushort      xUInt16   = 8;
    uint        xUInt32   = 9;
    ulong       xUInt64   = 10;
    sbyte       xSByte    = -11;
//
    Console.WriteLine("StringBuilder.Insert method");
    sb = new StringBuilder(initialValue);

    sb.Insert(3, xyz, 2);
    Show(1, sb);

    sb.Insert(3, xyz);
    Show(2, sb);

    sb.Insert(3, star);
    Show(3, sb);

    sb.Insert(3, abc);
    Show(4, sb);

    sb.Insert(3, abc, 1, 2);
    Show(5, sb);

    sb.Insert(3, xBool);     // True
    Show(6, sb);

    sb.Insert(3, obj);       // 0
    Show(7, sb);

    sb.Insert(3, xByte);     // 1
    Show(8, sb);

    sb.Insert(3, xInt16);    // 2
    Show(9, sb);

    sb.Insert(3, xInt32);    // 3
    Show(10, sb);

    sb.Insert(3, xInt64);    // 4
    Show(11, sb);

    sb.Insert(3, xDecimal);  // 5
    Show(12, sb);

    sb.Insert(3, xSingle);   // 6.6
    Show(13, sb);

    sb.Insert(3, xDouble);   // 7.7
    Show(14, sb);

// The following Insert methods are not CLS-compliant.
    sb.Insert(3, xUInt16);   // 8
    Show(15, sb);

    sb.Insert(3, xUInt32);   // 9
    Show(16, sb);

    sb.Insert(3, xUInt64);   // 10
    Show(17, sb);

    sb.Insert(3, xSByte);    // -11
    Show(18, sb);
//
    }

    public static void Show(int overloadNumber, StringBuilder sbs)
    {
    Console.WriteLine("{0,2:G} = {1}", overloadNumber, sbs.ToString());
    sb = new StringBuilder(initialValue);
    }
}
/*
This example produces the following results:

StringBuilder.Insert method
 1 = --[xyzxyz]--
 2 = --[xyz]--
 3 = --[*]--
 4 = --[abc]--
 5 = --[bc]--
 6 = --[True]--
 7 = --[0]--
 8 = --[1]--
 9 = --[2]--
10 = --[3]--
11 = --[4]--
12 = --[5]--
13 = --[6.6]--
14 = --[7.7]--
15 = --[8]--
16 = --[9]--
17 = --[10]--
18 = --[-11]--

*/

[C++] 
// This example demonstrates StringBuilder.Insert()
#using <mscorlib.dll>
using namespace System;
using namespace System::Text;

__gc class Sample 
{
//                           index: 012345
    static String* initialValue = S"--[]--";
    static StringBuilder* sb;
public:
    static void Main() 
    {
    String*     xyz       = S"xyz";
    Char abc[]            = {'a', 'b', 'c'};
    Char        star      = '*';
    Object*     obj       = __box(0);

    bool        xBool     = true;
    Byte        xByte     = 1;
    short       xInt16    = 2;
    int         xInt32    = 3;
    long        xInt64    = 4;
    Decimal     xDecimal  = 5;
    float       xSingle   = 6.6F;
    double      xDouble   = 7.7;

// The following types are not CLS-compliant.
    UInt16      xUInt16   = 8;
    UInt32      xUInt32   = 9;
    UInt64      xUInt64   = 10;
    SByte       xSByte    = -11;
//
    Console::WriteLine(S"StringBuilder.Insert method");
    sb = new StringBuilder(initialValue);

    sb->Insert(3, xyz, 2);
    Show(1, sb);

    sb->Insert(3, xyz);
    Show(2, sb);

    sb->Insert(3, star);
    Show(3, sb);

    sb->Insert(3, abc);
    Show(4, sb);

    sb->Insert(3, abc, 1, 2);
    Show(5, sb);

    sb->Insert(3, xBool);     // True
    Show(6, sb);

    sb->Insert(3, obj);       // 0
    Show(7, sb);

    sb->Insert(3, xByte);     // 1
    Show(8, sb);

    sb->Insert(3, xInt16);    // 2
    Show(9, sb);

    sb->Insert(3, xInt32);    // 3
    Show(10, sb);

    sb->Insert(3, xInt64);    // 4
    Show(11, sb);

    sb->Insert(3, xDecimal);  // 5
    Show(12, sb);

    sb->Insert(3, xSingle);   // 6.6
    Show(13, sb);

    sb->Insert(3, xDouble);   // 7.7
    Show(14, sb);

// The following Insert methods are not CLS-compliant.
    sb->Insert(3, xUInt16);   // 8
    Show(15, sb);

    sb->Insert(3, xUInt32);   // 9
    Show(16, sb);

    sb->Insert(3, xUInt64);   // 10
    Show(17, sb);

    sb->Insert(3, xSByte);    // -11
    Show(18, sb);
//
    }

    static void Show(int overloadNumber, StringBuilder* sbs)
    {
    Console::WriteLine(S"{0,2:G} = {1}", __box(overloadNumber),sbs);
    sb = new StringBuilder(initialValue);
    }
};

int main()
{
    Sample::Main();
}
/*
This example produces the following results:

StringBuilder.Insert method
 1 = --[xyzxyz]--
 2 = --[xyz]--
 3 = --[*]--
 4 = --[abc]--
 5 = --[bc]--
 6 = --[True]--
 7 = --[0]--
 8 = --[1]--
 9 = --[2]--
10 = --[3]--
11 = --[4]--
12 = --[5]--
13 = --[6.6]--
14 = --[7.7]--
15 = --[8]--
16 = --[9]--
17 = --[10]--
18 = --[-11]--

*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

StringBuilder クラス | StringBuilder メンバ | System.Text 名前空間