开发者

ASP.NET All Upper Case String, bring to lower and Capitalise all words [duplicate]

开发者 https://www.devze.com 2023-03-15 02:43 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Convert all first letter to upper case, rest lower for each word
This question already has answers here: Closed 11 years ago.

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

精彩评论

暂无评论...
验证码 换一张
取 消