I want to format a string value by a certain format that the first letter
of it be in Uppercase
.
e.g:
string.Format("{0}", "myName"); //Output must be : "MyName"
How can I do it?
I want to format a string value by a certain format that the first letter
of it be in Uppercase
.
e.g:
string.Format("{0}", "myName"); //Output must be : "MyName"
How can I do it?
Please check MSDN for your case, see TextInfo.ToTitleCase Method .
string myString = "wAr aNd pEaCe";
TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
Console.WriteLine("\"{0}\" to titlecase: {1}", myString, myTI.ToTitleCase(myString));
If you only want to capitalise the first letter, maybe:
string s = string.Format("{0}", char.ToUpper(myname[0]) + myname.Substring(1));
Otherwise, to capitalise each word maybe use TextInfo.ToTitleCase
?
string s = string.Format("{0}",
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(myname));
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
Console.WriteLine("{0}", textInfo.ToTitleCase(myname));
string input = "myname";
var charArray = input.ToArray();
charArray[0] = char.ToUpper(charArray[0]);
string result = new string(charArray);