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 9字祝福语简短创意
17 新年孕妈祝福语简短
18 花童结婚祝福语大全简短