views:

344

answers:

4

Are there any built-in functions in .Net that allow to capitalize strings, or handling proper casing? I know there are some somewhere in the Microsoft.VB namespace, but I want to avoid those if possible.

I'm aware of functions like string.ToUpper and string.ToLower() functions however it affects the entire string. I am looking to something like this:

var myString = "micah";
myString = myString.Format(FormattingOptions.Capitalize) //Micah
+9  A: 

Just to throw another option into the mix. This will capitalize every word in the given string:

public static string ToTitleCase(string inputString)

{

   System.Globalization.CultureInfo cultureInfo =
   System.Threading.Thread.CurrentThread.CurrentCulture;
   System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
   return textInfo.ToTitleCase(inputString.ToLower());

}
BFree
This is very nice. Didn't know about it.
Josh
+3  A: 

There's

System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(string str)

to capitalize every word in a string. ToTitleCase

Greg
+2  A: 

There is a free library available... String Processing Library

chills42
+1  A: 

This works in VB.NET

StrConv(Input, VbStrConv.ProperCase)

Brian Boatright