|
Proper Case in C#
Published: 3/17/2008 |
|
While C# doesn't have any string functions built into it to enable proper casing of text, there is yet something available if you look in the System.Globalization namespace. The Culture.TextInfo class has a method called "ToTitleCase", whish effectively does the same thing. Here's an example:
C#:
string sProperCaseString = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase("some string value");
The problem with this method is that characters that are already upper case are ignored. So, you have to convert the incoming text to lower case first, as so:
C#:
string sProperCaseString = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase("SOME string value".ToLower());
Questions or Comments? .
VB to C# and C# to VB translation provided by Instant C# and Instant VB.