Skip to content

Instantly share code, notes, and snippets.

@jonathascosta
Created May 18, 2011 18:58
Show Gist options
  • Save jonathascosta/979266 to your computer and use it in GitHub Desktop.
Save jonathascosta/979266 to your computer and use it in GitHub Desktop.
String Extensions
using System.Linq;
using System.Text.RegularExpressions;
public static class StringExtensions
{
public static string ToUpper(this string name, string separator)
{
string upper = Regex
.Matches(name, "[A-Z][a-z]+")
.Cast<Match>()
.Select(m => m.Value)
.Aggregate((acc, s) => string.Concat(acc, separator, s))
.ToUpper();
return upper;
}
public static string ToPascal(this string name, char separator)
{
string pascal = name
.Split(separator)
.Select(s => char.ToUpper(s[0]) + s.Substring(1).ToLower())
.Aggregate((acc, s) => string.Concat(acc, "", s));
return pascal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment