C#中的Insert()方法
Insert()C#中的方法用于返回新字符串,在该实例中,在指定的索引位置插入了指定的字符串。
语法
语法如下-
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
热门推荐
3 修祖屋祝福语简短
9 聚餐会祝福语简短
10 订婚新发言简短祝福语
11 短祝福语简短暖心
12 放假的祝福语简短霸气
13 我想找祝福语大全简短
14 下雨开工吉祥祝福语简短
15 老师出国祝福语大全简短
16 医生节蛋糕祝福语简短
17 班级集体生日祝福语简短
18 钱包祝福语简短10字