共用方式為


StringBuilder.Insert 方法

定義

將指定物件的字串表示插入此實例中指定的字元位置。

多載

名稱 Description
Insert(Int32, String, Int32)

在此實例中插入一個或多個指定字串的副本,並位於指定字元位置。

Insert(Int32, UInt64)

在此實例中插入一個 64 位元無符號整數的字串表示,位置為指定的字元位置。

Insert(Int32, UInt32)

在此實例中插入一個 32 位元無符號整數的字串表示,位置為指定的字元位置。

Insert(Int32, UInt16)

在此實例中插入 16 位元無符號整數的字串表示,位置為指定字元位置。

Insert(Int32, Rune)
Insert(Int32, String)

在指定的字元位置插入一個字串。

Insert(Int32, Char[], Int32, Int32)

將指定 Unicode 子陣列的字串表示插入此實例中指定的字元位置。

Insert(Int32, Single)

在指定字元位置插入單精度浮點數的字串表示。

Insert(Int32, SByte)

在此實例中插入指定的 8 位元有符號整數的字串表示,並指定字元位置。

Insert(Int32, ReadOnlySpan<Char>)

將該字元序列插入該實例中指定的字元位置。

Insert(Int32, Int16)

在此實例中插入指定的 16 位元有號整數字串表示,並於指定字元位置。

Insert(Int32, Int64)

在此實例中插入一個 64 位元有符號整數的字串表示,位置為指定字元。

Insert(Int32, Int32)

在此實例中插入指定的 32 位元有號整數的字串表示,並指定字元位置。

Insert(Int32, Double)

在此實例中,將雙精度浮點數的字串表示法插入指定的字元位置。

Insert(Int32, Decimal)

在指定字元位置插入十進位數的字串表示。

Insert(Int32, Char[])

將指定 Unicode 字元陣列的字串表示插入此實例中指定的字元位置。

Insert(Int32, Char)

將指定 Unicode 字元的字串表示插入此實例中指定的字元位置。

Insert(Int32, Byte)

在此實例中插入指定的 8 位元無符號整數字串表示,並指定字元位置。

Insert(Int32, Boolean)

在指定字元位置插入布林值的字串表示。

Insert(Int32, Object)

在指定的字元位置插入物件的字串表示。

範例

以下範例示範此 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]--

*/
open System.Text

let initialValue = "--[]--"

let show overloadNumber (sbs: StringBuilder) =
    printfn $"{overloadNumber, 2:G} = {sbs}"
    sbs.Clear().Append initialValue |> ignore

let xyz = "xyz"
let abc = [| 'a'; 'b'; 'c' |]
let star = '*'
let obj: obj = 0

let xBool = true
let xByte = 1uy
let xInt16 = 2s
let xInt32 = 3
let xInt64 = 4L
let xDecimal = 5M
let xSingle = 6.6f
let xDouble = 7.7

// The following types are not CLS-compliant.
let xUInt16 = 8us
let xUInt32 = 9u
let xUInt64 = 10uL
let xSByte = -11y

printfn "StringBuilder.Insert method"
let sb = StringBuilder initialValue

sb.Insert(3, xyz, 2) |> ignore
show 1 sb

sb.Insert(3, xyz) |> ignore
show 2 sb

sb.Insert(3, star) |> ignore
show 3 sb

sb.Insert(3, abc) |> ignore
show 4 sb

sb.Insert(3, abc, 1, 2) |> ignore
show 5 sb

sb.Insert(3, xBool) |> ignore // True
show 6 sb

sb.Insert(3, obj) |> ignore // 0
show 7 sb

sb.Insert(3, xByte) |> ignore // 1
show 8 sb

sb.Insert(3, xInt16) |> ignore // 2
show 9 sb

sb.Insert(3, xInt32) |> ignore // 3
show 10 sb

sb.Insert(3, xInt64) |> ignore // 4
show 11 sb

sb.Insert(3, xDecimal) |> ignore // 5
show 12 sb

sb.Insert(3, xSingle) |> ignore // 6.6
show 13 sb

sb.Insert(3, xDouble) |> ignore // 7.7
show 14 sb

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

sb.Insert(3, xUInt32) |> ignore // 9
show 16 sb

sb.Insert(3, xUInt64) |> ignore // 10
show 17 sb

sb.Insert(3, xSByte) |> ignore // -11
show 18 sb

// 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]--
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
   
   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
End Class
'
'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]--
'

Insert(Int32, String, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中插入一個或多個指定字串的副本,並位於指定字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, System::String ^ value, int count);
public System.Text.StringBuilder Insert(int index, string value, int count);
public System.Text.StringBuilder Insert(int index, string? value, int count);
member this.Insert : int * string * int -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As String, count As Integer) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
String

要插入的字串。

count
Int32

插入 value的次數。

傳回

插入完成後的此實例參考。

例外狀況

index 小於零或大於此實例目前的長度。

-或-

count 小於零。

這個StringBuilder物件的當前長度加上時間valuecount長度超過MaxCapacity了。

備註

現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

當 是 ,value且其null長度為零,或count為零時,該StringBuilder物件不會null改變。value

另請參閱

適用於

Insert(Int32, UInt64)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中插入一個 64 位元無符號整數的字串表示,位置為指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, System::UInt64 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Insert(int index, ulong value);
[<System.CLSCompliant(false)>]
member this.Insert : int * uint64 -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As ULong) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
UInt64

要插入的值。

傳回

插入操作完成後,參考此實例。

屬性

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

UInt64.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, UInt32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中插入一個 32 位元無符號整數的字串表示,位置為指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, System::UInt32 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Insert(int index, uint value);
[<System.CLSCompliant(false)>]
member this.Insert : int * uint32 -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As UInteger) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
UInt32

要插入的值。

傳回

插入操作完成後,參考此實例。

屬性

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

UInt32.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, UInt16)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中插入 16 位元無符號整數的字串表示,位置為指定字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, System::UInt16 value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Insert(int index, ushort value);
[<System.CLSCompliant(false)>]
member this.Insert : int * uint16 -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As UShort) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
UInt16

要插入的值。

傳回

插入操作完成後,參考此實例。

屬性

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

UInt16.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Rune)

public:
 System::Text::StringBuilder ^ Insert(int index, System::Text::Rune value);
public System.Text.StringBuilder Insert(int index, System.Text.Rune value);
member this.Insert : int * System.Text.Rune -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Rune) As StringBuilder

參數

index
Int32
value
Rune

傳回

適用於

Insert(Int32, String)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在指定的字元位置插入一個字串。

public:
 System::Text::StringBuilder ^ Insert(int index, System::String ^ value);
public System.Text.StringBuilder Insert(int index, string value);
public System.Text.StringBuilder Insert(int index, string? value);
member this.Insert : int * string -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As String) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
String

要插入的字串。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例目前的長度。

-或-

StringBuilder 物件的當前長度加上 的 value 長度超過 MaxCapacity

備註

現有字元會被移動,以騰出空間給新文字。 容量會根據需要調整。

value 為 ,nullvalue 為 ,且其null長度為零,則 不StringBuilder改變。

另請參閱

適用於

Insert(Int32, Char[], Int32, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定 Unicode 子陣列的字串表示插入此實例中指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, cli::array <char> ^ value, int startIndex, int charCount);
public System.Text.StringBuilder Insert(int index, char[] value, int startIndex, int charCount);
public System.Text.StringBuilder Insert(int index, char[]? value, int startIndex, int charCount);
member this.Insert : int * char[] * int * int -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Char(), startIndex As Integer, charCount As Integer) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Char[]

一個字元陣列。

startIndex
Int32

起始指標。value

charCount
Int32

要插入的字元數量。

傳回

插入操作完成後,參考此實例。

例外狀況

valuenull、 和 startIndexcharCount 都不是零。

indexstartIndex, , charCount 小於零。

-或-

index 大於此實例的長度。

-或-

startIndex plus charCount 不是 內的 value一個位置。

-或-

擴大此實例的值將超過 MaxCapacity

備註

現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

適用於

Insert(Int32, Single)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在指定字元位置插入單精度浮點數的字串表示。

public:
 System::Text::StringBuilder ^ Insert(int index, float value);
public System.Text.StringBuilder Insert(int index, float value);
member this.Insert : int * single -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Single) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Single

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Single.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, SByte)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

重要

此 API 不符合 CLS 規範。

在此實例中插入指定的 8 位元有符號整數的字串表示,並指定字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, System::SByte value);
[System.CLSCompliant(false)]
public System.Text.StringBuilder Insert(int index, sbyte value);
[<System.CLSCompliant(false)>]
member this.Insert : int * sbyte -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As SByte) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
SByte

要插入的值。

傳回

插入操作完成後,參考此實例。

屬性

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

SByte.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, ReadOnlySpan<Char>)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將該字元序列插入該實例中指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, ReadOnlySpan<char> value);
public System.Text.StringBuilder Insert(int index, ReadOnlySpan<char> value);
member this.Insert : int * ReadOnlySpan<char> -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As ReadOnlySpan(Of Char)) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
ReadOnlySpan<Char>

字元跨度至插入。

傳回

插入操作完成後,參考此實例。

備註

現有字元會被移動,以便插入該角色序列 value 。 容量會根據需要調整。

適用於

Insert(Int32, Int16)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中插入指定的 16 位元有號整數字串表示,並於指定字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, short value);
public System.Text.StringBuilder Insert(int index, short value);
member this.Insert : int * int16 -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Short) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Int16

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Int16.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Int64)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中插入一個 64 位元有符號整數的字串表示,位置為指定字元。

public:
 System::Text::StringBuilder ^ Insert(int index, long value);
public System.Text.StringBuilder Insert(int index, long value);
member this.Insert : int * int64 -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Long) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Int64

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Int64.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Int32)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中插入指定的 32 位元有號整數的字串表示,並指定字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, int value);
public System.Text.StringBuilder Insert(int index, int value);
member this.Insert : int * int -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Integer) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Int32

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Int32.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Double)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中,將雙精度浮點數的字串表示法插入指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, double value);
public System.Text.StringBuilder Insert(int index, double value);
member this.Insert : int * double -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Double) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Double

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Double.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Decimal)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在指定字元位置插入十進位數的字串表示。

public:
 System::Text::StringBuilder ^ Insert(int index, System::Decimal value);
public System.Text.StringBuilder Insert(int index, decimal value);
member this.Insert : int * decimal -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Decimal) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Decimal

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Decimal.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Char[])

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定 Unicode 字元陣列的字串表示插入此實例中指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, cli::array <char> ^ value);
public System.Text.StringBuilder Insert(int index, char[] value);
public System.Text.StringBuilder Insert(int index, char[]? value);
member this.Insert : int * char[] -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Char()) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Char[]

要插入的字元陣列。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

-或-

擴大此實例的值將超過 MaxCapacity

備註

現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

valuenullStringBuilder 不改變。

適用於

Insert(Int32, Char)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

將指定 Unicode 字元的字串表示插入此實例中指定的字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, char value);
public System.Text.StringBuilder Insert(int index, char value);
member this.Insert : int * char -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Char) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Char

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

-或-

擴大此實例的值將超過 MaxCapacity

備註

Char.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

另請參閱

適用於

Insert(Int32, Byte)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在此實例中插入指定的 8 位元無符號整數字串表示,並指定字元位置。

public:
 System::Text::StringBuilder ^ Insert(int index, System::Byte value);
public System.Text.StringBuilder Insert(int index, byte value);
member this.Insert : int * byte -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Byte) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Byte

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Byte.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Boolean)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在指定字元位置插入布林值的字串表示。

public:
 System::Text::StringBuilder ^ Insert(int index, bool value);
public System.Text.StringBuilder Insert(int index, bool value);
member this.Insert : int * bool -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Boolean) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Boolean

要插入的值。

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Boolean.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 容量會根據需要調整。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於

Insert(Int32, Object)

來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs
來源:
StringBuilder.cs

在指定的字元位置插入物件的字串表示。

public:
 System::Text::StringBuilder ^ Insert(int index, System::Object ^ value);
public System.Text.StringBuilder Insert(int index, object value);
public System.Text.StringBuilder Insert(int index, object? value);
member this.Insert : int * obj -> System.Text.StringBuilder
Public Function Insert (index As Integer, value As Object) As StringBuilder

參數

index
Int32

此處插入開始的位置。

value
Object

要插入的物件,或 null

傳回

插入操作完成後,參考此實例。

例外狀況

index 小於零或大於此實例的長度。

擴大此實例的值將超過 MaxCapacity

備註

Object.ToString 用來得到 的 value字串表示。 現有字元會被移動,以騰出空間給新文字。 此實例的容量會根據需要調整。

valuenull則該實例的值保持不變。

給呼叫者的注意事項

在 .NET Framework 3.5 Service Pack 1 及更早版本中,呼叫此方法會 ArgumentOutOfRangeException 拋出 if value 插入,導致物件總長度超過 MaxCapacity。 從 .NET Framework 4 開始,該方法會拋出一個 OutOfMemoryException.

另請參閱

適用於