Split string by multiple character delimiter in asp.net

In this article you will learn how to split string by multiple character delimiter in asp.net. Well it is very simple and we can do it by using the built-in split () function of asp.net. Let's have a look on its implementation.
 
        string actualURL = "http://mywebsite.com/aboutus.aspx/images/test.aspx";
        string[] parts1 = actualURL.Split(new string[] { ".aspx" }, StringSplitOptions.None);

So that's it. In this example we have a wrong url containing two pages name and we have to get the first page so we have split the url by ".aspx" delimeter and store the result in parts1 array. 

Another method to do this task is by using Regex
 
string[] parts2 = Regex.Split(actualURL, @".aspx");

Note: Make sure to use using System.Text.RegularExpressions for using Regex.

Happy Coding!!!

0 comments: