Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built-In Character Casing functions in .Net

Tags:

string

c#

.net

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
like image 326
Micah Avatar asked Dec 05 '22 07:12

Micah


1 Answers

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());

}
like image 59
BFree Avatar answered Dec 07 '22 19:12

BFree