aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Regex Split String but Keep Delimiter in C#, VB.NET

Feb 1, 2017

Here we will learn how to split string include delimiters in c#, with example or split string but keep delimiters in c#, with example or regex split string but keep delimiter at the end in c#, with example or split string into array of words but keep delimiters at the end of result in c#, with example. By using regular expression we can easily split the string and include delimiters in word based on our requirements.


By using regular expressions we can easily split and keep the delimiters at the end of string. Following is the sample code snippet to split the string with delimiters “?@!”.

C# Code

string text = "suresh?rohini@praveen!sateesh";
string[] split = Regex.Split(text, @"(?<=[?@!])");


Dim text As [String] = "suresh?rohini@praveen!sateesh"
Dim split As String() = Regex.Split(text, "(?<=[?@!])")

When we execute above statements we will get result like as shown below.

Regex Split String but Keep Delimiter in C#, VB.NET

If you want complete example to split string but to keep delimiter create new project and write the code like as shown below.

C# Code

using System;
using System.Text.RegularExpressions;

namespace SampleConsoleApp
class Program
static void Main(string[] args)
string text = "suresh?rohini@praveen!sateesh";
string[] strarr = Regex.Split(text, @"(?<=[?@!])");
foreach (var item in strarr)


Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim text As String = "suresh?rohini@praveen!sateesh"
Dim strarr As String() = Regex.Split(text, "(?<=[?@!])")
For Each item In strarr
End Sub
End Module

If you observe above examples we are splitting string with special characters “?@!”.


Now run the application to see the result that will be like as shown below. Following is the result of splitting the string and including delimiter at the end of string.

This is how we can split the string into words including delimiters in

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.