0

Possible Duplicate:
Convert all first letter to upper case, rest lower for each word

Hey currently I am receiving a string i.e. company name in all caps.

I want to make this more userfriendly and was thinking of just bringing the first letter of all words to uppercase.

i.e

Then im just wondering how it would work for cases such as

SKILLSHARE INTERNATIONAL (IRELAND)

CITY OF DUBLIN YOUNG MEN'S CHRISTIAN ASSOCIATION LIMITED

Community
  • 1
  • 1
StevieB
  • 6,263
  • 38
  • 108
  • 193

2 Answers2

1
public static string Capitalize (string value)
{
    return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase (value);
}
JonH
  • 32,732
  • 12
  • 87
  • 145
  • 1
    The MSDN article on ToTitleCase is hilarious. It explains that the casing isn't linguistically correct for titles for performance reasons, but, "We reserve the right to make this API slower in the future." LMAO http://msdn.microsoft.com/en-us/library/system.globalization.textinfo.totitlecase.aspx – pseudocoder Jun 23 '11 at 13:41
0

If you want to create your own function then use this code

string str = "CITY OF DUBLIN YOUNG MEN'S CHRISTIAN ASSOCIATION LIMITED";
char[] ch = { ' ' };
string[] str1 = str.Split(ch, StringSplitOptions.RemoveEmptyEntries);
string result = string.Empty;
foreach (string s in str1)
{
    result += s[0].ToString().ToUpper() + s.Substring(1, s.Length - 1).ToLower() + " ";
}
Response.Write(result);
Gaurav Agrawal
  • 4,355
  • 10
  • 42
  • 61