I recently saw a post asking if there was a way to change a string so it started with an uppercase and had lowercase following. Here looks to be the best solution:
public static class StringHelper {
public static string ToTitleCase(string text) {
return StringHelper.ToTitleCase(text, CultureInfo.InvariantCulture);
}
public static string ToTitleCase(string text, CultureInfo cultureInfo) {
if (string.IsNullOrEmpty(text)) return string.Empty;
TextInfo textInfo = cultureInfo.TextInfo;
return textInfo.ToTitleCase(text.ToLower());
}
}
What I would like is to convert these into string extensions. Can someone suggest how I can do this?
Use the
thiskeyword in front of the first parameter:See How to: Implement and Call a Custom Extension Method (C# Programming Guide) on MSDN.