String.Insert()方法以及C#中的示例
C#方法String.Insert()
String.Insert()方法用于在指定索引处的存在字符串中插入字符串并返回新字符串。
语法:
public string String.Insert(int index, string value);
用“this”字符串调用该方法,即我们必须在其中插入字符串的字符串。
Parameter(s):
index–表示当前字符串的索引/位置,要在其中插入新的字符串值。
value–要插入的新字符串。
返回值:
string–返回一个新字符串,其中包含在给定索引处插入的字符串。
示例
Input:
string str = "nhooo";
string str1 = " programming ";
Function call
str.Insert(7, str1);
Output:
Include programming HelpC#使用String.Insert()方法将字符串转换为字符数组的示例
范例1:
using System;
class nhooo
{
static void Main()
{
// 声明字符串变量
string str = "nhooo";
// 在“包含”和“帮助”之间插入空格
string new_string = str.Insert(7, " ");
Console.WriteLine("str: " + str);
Console.WriteLine("new_string: " + new_string);
}
}输出结果
str: nhooo new_string: Include Help
范例2:
using System;
class Nhooo
{
static void Main()
{
// 声明字符串变量
string str = "nhooo";
string str1 = " programming ";
// 在“包含”之后插入str1"Include"
string new_string = str.Insert(7, str1);
Console.WriteLine("str: " + str);
Console.WriteLine("new_string: " + new_string);
}
}输出结果
str: nhooo new_string: Include programming Help
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短