To split and join strings in C#, use the split() and join() methods. Suppose the following is our string -
string str = "This is our Demo String";
To split the string we will use split() method -
var arr = str.Split(' ');
Now to join use join() method and join the strings The rest. Here we are skipping a part of the string using skip() method -
string rest = string.Join(" ", arr.Skip(1));
You can try running the following code in C# to split and concatenate the string.
Real-time demonstration< /p>
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
The above is the detailed content of C# program to split and concatenate strings. For more information, please follow other related articles on the PHP Chinese website!