当前位置: 代码迷 >> ASP.NET >> 把英文的第一个字母转换成大写,该如何解决
  详细解决方案

把英文的第一个字母转换成大写,该如何解决

热度:4916   发布时间:2013-02-26 00:00:00.0
把英文的第一个字母转换成大写
如把
are   you   kidding   me?
转换成
Are   You   Kidding   Me?



------解决方案--------------------------------------------------------
public static string strLast = " ";
private void Form1_Load(object sender, EventArgs e)
{
string strEng = "are you kidding me? ";
string[] strItem = strEng.Split(char.Parse( " "));
for (int i = 0; i < strItem.Length ; i++)
{
string strUp = strItem[i];
string strEngFirst = strUp.Substring(0, 1).ToUpper();
string strEngEnd = strUp.Substring(1, (strUp.Length - 1));
strUp = strEngFirst + strEngEnd;
strLast = strLast + " " + strUp;
}
}
------解决方案--------------------------------------------------------
string str = "are you kidding me? ";
string[] substrings = str.split( " ");
str = " ";
for(int i=0;i <substrings.Length;i++)
{
substrings[i] = substrings[i].Substring(0,1).ToUpper() + substrings[i].Substring(1,substrings[i].Length-1);
str += substrings[i] + " ";
}
str = str.Substring(0,str.Length-1);
这个有点像MS的面试题
  相关解决方案