
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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!
- Related Articles
- How to split a String into an array in Kotlin?
- How to split comma and semicolon separated string into a two-dimensional array in JavaScript ?
- How to split a Java String into tokens with StringTokenizer?
- How to split a string column into multiple columns in R?
- PHP program to split a given comma delimited string into an array of values
- How to split a string with a string delimiter in C#?
- How to split string by a delimiter string in Python?
- How to extract the split string elements in R?
- How to split a long string into a vector of substrings of equal sizes in R?
- How to split a string in Python
- How to split a string in Java?
- How to split a string in Golang?
- Split string into groups - JavaScript
- How do I split a multi-line string into multiple lines?
- How to split a string in Lua programming?

Advertisements