當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C# String Insert()用法及代碼示例

C# Insert() 方法用於在指定的索引號處插入指定的字符串。索引號從0開始,插入指定的字符串後,返回一個新的修改後的字符串。

簽名

public string Insert(Int32 first, String second)

參數

first:它用於作為索引傳遞。

second:它用於在指定的索引處插入給定的字符串。

返回

它返回一個新的修改後的字符串。

C# 字符串 Insert() 方法示例

using System;  
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
          string s1 = "Hello C#";
          string s2 = s1.Insert(5,"-");
          Console.WriteLine(s2);
        }  
    }

輸出:

Hello- C#




相關用法


注:本文由純淨天空篩選整理自 C# String Insert()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。