Created
May 18, 2011 18:58
-
-
Save jonathascosta/979266 to your computer and use it in GitHub Desktop.
String Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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