C#程序拆分和连接字符串
要在C#中拆分和连接字符串,请使用split()andjoin()方法。让我们说以下是我们的字符串-
string str = "This is our Demo String";
为了分割字符串,我们将使用split()方法-
var arr = str.Split(' ');现在开始联接,使用join()方法并联接字符串的其余部分。在这里,我们使用skip()方法跳过了字符串的一部分-
string rest = string.Join(" ", arr.Skip(1));示例
您可以尝试在C#中运行以下代码以拆分和连接字符串。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
string str = "This is our Demo String";
var arr = str.Split(' ');
//跳过第一个元素并加入数组的其余部分
string rest = string.Join(" ", arr.Skip(1));
Console.WriteLine(rest);
}
}
}输出结果
is our Demo String
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短