Skip to content

class StringExtensions

nagahoge edited this page Dec 1, 2012 · 2 revisions

string[] String#Split(string separator, int limit = 0)

Same as Ruby's String#split method.

Example

string[] splittedString = 
    "I am a pen.<br />You are also a pen.<br />He is not a pen.".Split("<br />");
// splittedString: {"I am a pen.", "You are also a pen.", "He is not a pen."}

Word splitting

Same as Ruby's String#split method, passing null or String.Empty value for separator parameter, split string for each word.

string[] words = "I am a pen.".Split(null);
// words : {"I", "am", "a", "pen."}

If write same logick in C# basic expression.

string[] splittedString =
    "I am a pen.<br />You are also a pen.<br />He is not a pen.".Split(
        new string[] {"<br />"}, StringSplitOptions.None);