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

SplitPascalCase

Splits the given string by pascal case.

Source

/*
Requires a reference System.Text.RegularExpressions.
*/

/// <summary>
/// Splits the string by pascal case.
/// </summary>
/// <param name="text">The text.</param>
/// <returns></returns>
public static string SplitPascalCase(this string text)
{
    if (string.IsNullOrEmpty(text))
    {
        return text;
    }
    return Regex.Replace(text, "([A-Z])", " $1", RegexOptions.Compiled).Trim();
}

Example

var str = "ThisIsAPascalCaseString";
return str.SplitPascalCase();

/*
"This Is A Pascal Case String"
*/

Author: Sheraz Naseeb

Submitted on: 15 nov 2016

Language: C#

Type: String

Views: 1651