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
以上就是c# 程序来分割和连接字符串的详细内容。
