Dirk Bergmann

Developer, panographer. Does consultancy work from own company. Lives in Chiang Mai, Thailand.

Twitter

Chiang Mai

Hua Hin

Thailand Hotels

ListVote - List. Vote. Learn.

Partnerseek - Find Partners

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.