C# 中的 Insert() 方法
C# 中的 Insert() 方法用于返回一个新字符串,其中指定字符串插入本实例中指定索引位置。
语法
语法如下 -
public string Insert (int begnIndex, string val);
在上面,参数 begnIndex 是插入的从零开始的索引位置,而 val 是要插入的字符串。
实例
现在让我们看一个实例 -
using System;
public class Demo{
public static void Main(){
String str = "JohnWick";
Console.WriteLine("Initial string = "+str);
String res = str.Insert(5, " ");
Console.WriteLine("Updated = "+res);
}
}输出
这将产生以下输出 -
Initial string = JohnWick Updated = JohnW ick
实例
现在让我们看另一个示例
using System;
public class Demo{
public static void Main(){
String str = "WelcomeJacob";
Console.WriteLine("Initial string = "+str);
String res = str.Insert(7, " here, ");
Console.WriteLine("Updated = "+res);
}
}输出
这将产生以下输出 -
Initial string = WelcomeJacob Updated = Welcome here, Jacob
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP