ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

SplitCamelCase

Split any string using camel case pattern.

Source

public static IEnumerable<string> SplitCamelCase(this string source)
{
    const string pattern = @"[A-Z][a-z]*|[a-z]+|\d+";
    var matches = Regex.Matches(source, pattern);
    foreach (Match match in matches)
    {
        yield return match.Value;
    }
}

Example

string stringForSplit = "CamelCaseString";
IEnumerable<string> splittedString = stringForSplit.SplitCamelCase();
// Result: collection with the strings "Camel" "Case" "String"

Author: Piero Alvarez Fuentes

Submitted on: 3 aug. 2018

Language: C#

Type: System.String

Views: 8142