Dirk Dot Net

Creator of useful things. Based in Chiang Mai, Northern Thailand.

Capitalize with C and ASP.NET

It may be surprising for some, but the .NET framework has capitalization built in:

**using System.Globalization;
class Test

{public static void Main ()
{
string s =
CultureInfo.CurrentCulture.TextInfo.ToTitleCase ("i want this capitalized or capitalised if possible.");
Console.WriteLine (s);
}
}**

It's even easier with VB.NET:

StrConv(yourTextvalue, VbStrConv.ProperCase)

Still not as elegant as capitalize(str) in Rails ActiveSupport, but the approach via globalize might be more maintainable in the long run. Some dislike though, so your mileage may vary.