public static string ToPascalCase(this string text)
{
text = text.Replace("_", " ").Trim();
if (string.IsNullOrEmpty(text))
return String.Empty;
var newText = new StringBuilder(text.Length * 2);
newText.Append(text[0].ToString(CultureInfo.InvariantCulture).ToUpper());
for (var i = 1; i < text.Length; i++)
{
if (char.IsWhiteSpace(text[i]))
continue;
var prev = text[i - 1];
if (char.IsWhiteSpace(prev) || char.IsNumber(prev))
newText.Append(text[i].ToString(CultureInfo.InvariantCulture).ToUpper());
else
newText.Append(text[i]);
}
return newText.ToString();
}