ASP.NET All Upper Case String, bring to lower and Capitalise all words [duplicate]
Possible Duplicate:
Convert all first letter to upper case, rest lower for each word
Hey 开发者_如何学Gocurrently 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
public static string Capitalize (string value)
{
return System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase (value);
}
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);
精彩评论