Introduction:
Here we will learn how to split
string include delimiters in c#,
vb.net with example or split string but keep delimiters in c#,
vb.net with example or regex split string but keep delimiter at
the end in c#,
vb.net with example or split string into array of words but keep
delimiters at the end of result in c#,
vb.net with example. By using regular expression we
can easily split the string and include delimiters in word based on our
requirements.
Description:
In previous articles I explained split string example in c#, vb.net, use split function in jquery to split the string, jQuery get query string values with special characters, sql server check if string contains specific word / string,
jQuery split string into array with comma delimiter example,
sql server split function to split string with example and
many articles related to in JSON,
asp.net,
mvc, c#,
vb.net.
Now I will explain how to split the string and keep the delimiters at the end in
c#,
vb.net
with example.
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, @"(?<=[?@!])");
|
VB.NET
Code
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.
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)
Console.WriteLine(item);
Console.ReadLine();
}
}
}
|
VB.NET Code
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
Console.WriteLine(item)
Next
Console.ReadLine()
End Sub
End Module
|
If you observe above examples we are splitting string
with special characters “?@!”.
Demo
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.
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.