- 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 a string on spaces
Firstly, set a string −
string str = "Science and Mathematics";
Now use the Split() method to split wherever the spaces occur −
str.Split(' ')
The following is the complete code −
Example
using System; using System.Linq; using System.IO; class Program { static void Main() { string str = "Science and Mathematics"; Console.WriteLine("String...
"+str); string[] myStr = str.Split(' '); Console.WriteLine("
Splitted String..."); foreach (string ch in myStr) { Console.WriteLine(ch); } } }
Output
String... Science and Mathematics Splitted String... Science and Mathematics
- Related Articles
- C++ Program to remove spaces from a string?
- C++ program to remove spaces from a string using String stream
- C# program to split and join a string
- C# program to replace all spaces in a string with ‘%20’
- C program to remove spaces in a sentence using string concepts.
- C program to remove extra spaces using string concepts.
- Python program to split and join a string?
- Java Program to split a string with dot
- Java program to split and join a string
- Java Program to remove all white spaces from a String.
- Split Space Delimited String and Trim Extra Commas and Spaces in JavaScript?
- Java Program to split a string using Regular Expression
- C Program to count vowels, digits, spaces, consonants using the string concepts
- How to split a string with a string delimiter in C#?
- How to split string on whitespace in Python?

Advertisements