Fri, 17 May 2024


How to use the static Regex.Split() to split strings in C# ?

By: Anton, NetArt Media
Fri, 28 January 2022

As you might know the string Split method allows you to split astring only be a specified character. If you wish to split a string using the power of the regular expressions to specify the delimiter a good solution is to use the Regex.Split() method

using System.Text;
using System.Text.RegularExpressions;


string strText=" Development @@ of @@ online @@ pharmacy @@ web @@ solutions ";

foreach(string strItem in Regex.Split(strText,"@@"))
{
Console.WriteLine(strItem);
}


will print:

Development
of
online
pharmacy
web
solutions


Category: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox