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
How to split a string into elements of a string array in C#?
Set the string you want to split.
string str = "Hello World!";
Use the split() method to split the string into separate elements.
string[] res = str.Split(' ');
The following is the complete code to split a string into elements of a string array in C#.
Example
using System;
class Demo {
static void Main() {
string str = "Hello World!";
string[] res = str.Split(' ');
Console.WriteLine("Separate elements:");
foreach (string words in res) {
Console.WriteLine(words);
}
}
}
Output
Separate elements: Hello World!
Advertisements