- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- Python program to split and join a string?
- Java program to split and join a string
- Python program to split a string and join with comma
- C# Program to split a string on spaces
- C# program to join words into a string in C#
- Java Program to split a string with dot
- Java regex program to split a string at every space and punctuation.
- Java Program to split a string using Regular Expression
- How to split a string with a string delimiter in C#?
- Program to find number of ways to split a string in Python
- How to split a string into elements of a string array in C#?
- Python program to split string into k distinct partitions
- How to split a string using regular expressions in C#?
- Java regex program to split a string with line endings as delimiter
- Program to find number of good ways to split a string using Python

Advertisements