C# explode function like in php

Just for note.

If you need the php explode function in C#,  you can use the following code:

public static string[] explode(string separator, string source) {
    return source.Split(new string[] { separator }, StringSplitOptions.None);
}

How to use it:

string[] resultsArray = StringUtils.explode("|","blah1|blah2|blah3");

The resulting array will contain the following 3 elements:
resultsArray[0]="blah1";
resultsArray[1]="blah2";
resultsArray[2]="blah3";

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

One thought on “C# explode function like in php”

  1. You could also just initialize the more common way:
    string[] text =
    {
    “blah1”,
    “blah2”,
    “blah3”
    };

    Or a one-liner:
    string[] text = { “blah1”, “blah2”, “blah3” };

Leave a Reply

Your email address will not be published.

Exit mobile version
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.