C# 程序如何对字符串进行拆分和连接
要对 C# 中的字符串进行拆分和连接,请使用 split() 和 join() 方法。假定我们的字符串为以下内容 -
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(' ');
// skips the first element and joins rest of the array
string rest = string.Join(" ", arr.Skip(1));
Console.WriteLine(rest);
}
}
}输出
is our Demo String
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP