Capitalize with C# and ASP.NET

ASP.NET, C# Add comments

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.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in