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:

1 thought on “C# explode function like in php

  1. Me

    You could also just initialize the more common way:
    string[] text =

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


Leave a Reply

Your email address will not be published. Required fields are marked *