您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C# 程序来分割和连接字符串

2024/3/24 10:16:28发布19次查看
要在 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# 程序来分割和连接字符串的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product