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

CamelCaseToHumanCase

Turn any string formed with camel case into a human cased string.

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;
    }
}

public static string CamelCaseToHumanCase(this string source)
{
    var words = source.SplitCamelCase();
    string humanCased = string.Join(" ", words);
    return humanCased;
}

Example

string camelCaseString = "CamelCaseString";
string humanCased = stringForSplit.CamelCaseToHumanCase();
// Result: "Camel Case String"

Author: Piero Alvarez Fuentes

Submitted on: 3 aug 2018

Language: C#

Type: System.String

Views: 4703