
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to Split and Join a String
To split and join a string in C#, use the split() and join() method. Let us say the following is our string −
string str = "This is our Demo String";
To split the string, we will use the split() method −
var arr = str.Split(' ');
Now to join, use the join() method and join rest of the string. Here, we have skipped the part of the string using the skip() method −
string rest = string.Join(" ", arr.Skip(1));
Example
You can try to run the following code in C# to split and join a string.
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); } } }
Output
is our Demo String
Advertisements