要在 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
以上就是C# 程序来分割和连接字符串的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号