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