I want to format my string into Capitalize character formatting (i.e Capitalize First Char Of Words).
For Example -
If Input is: "NEW YORK CITY"
then the desired output is: "New York City"
*my string have maximum 3 words.
After, googled it i found several of ways to achieve this approach, but i can't get which is the best approach for this.
Method 1st:
string City = "NEW YORK CITY";
City = City.ToLower();
string Capatilize_City = "";
Capatilize_City = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(City);
Method 2nd:
string City = "NEW YORK CITY";
string[] lstWord = City.ToLower().Split(' ');
string Capatilize_City = "";
foreach (string s in lstWord)
{
string z = s.Substring(0, 1).ToUpper() + s.Substring(1, s.Length - 1);
Capatilize_City += " " + z;
}
Capatilize_City = Capatilize_City.Trim();
Which code is best for use (performance and speed vice)?