- 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
How to split a string using regular expressions in C#?
To split a string suing regular expression, use the Regex.split.
Let’s say our string is −
string str = "Hello\r
World";
Now use Regex.split to split the string as shown below −
tring[] res = Regex.Split(str, "\r
");
The following is the complete code to split a string using Regular Expression in C#.
Example
using System; using System.Text.RegularExpressions; class Demo { static void Main() { string str = "Hello\r
World"; string[] res = Regex.Split(str, "\r
"); foreach (string word in res) { Console.WriteLine(word); } } }
Output
Hello World
- Related Articles
- How to Split String in Java using Regular Expression?
- How to extract numbers from a string using regular expressions?
- Java Program to split a string using Regular Expression
- How to remove consonants from a string using regular expressions in Java?
- How to remove vowels from a string using regular expressions in Java?
- Return a specific MySQL string using regular expressions
- Remove Leading Zeroes from a String in Java using regular expressions
- How to extract data from a string with Python Regular Expressions?
- How to match whitespace in python using regular expressions
- How do we use a delimiter to split string in Python regular expression?
- How to split a string with a string delimiter in C#?
- MySQL Regular expressions: How to match digits in the string with d?
- How to split string in MySQL using SUBSTRING_INDEX?
- How to validate an email address using Java regular expressions.
- How to use regular expressions in a CSS locator?

Advertisements