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.

Posted: 28 May 2008

comments powered by Disqus