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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C语言
C++
C#
MongoDB
MySQL
Javascript
PHP