c#中怎么将字符串中每个词的第一个字母转换成大写,其他的转换成小写
比如将 HELLO,good,HoW 转换成 Hello,Good,How

解决方案 »

  1.   

    "good".ToUpper();这样就可以转换了...
      

  2.   

    转小写: "HELLO".ToLower();再用一个循环判断不是可以了吗
      

  3.   

    string test = "HELLO";
    string new = test.Substring(0,1).ToUpper() + test.Substring(1,test.Length-1).ToLower();get new is "Hello";
      

  4.   

    正则表达式我也不熟悉。随便写写。
    string strSrc = "show me the money";
                StringBuilder sb = new StringBuilder(strSrc.Length);
                MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w\W]*)");
                foreach (Match m in res)
                {
                    sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value);
                }
                string strDst = sb.ToString();
                MessageBox.Show(strDst);
      

  5.   

    贴错了。
    写好的,最后画蛇添足了一下。这个。下面的可以。
    string strSrc = "show me the money.during these days.";
                StringBuilder sb = new StringBuilder(strSrc.Length);
                MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?)");
                foreach (Match m in res)
                {
                    sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value);
                }
                string strDst = sb.ToString();
                MessageBox.Show(strDst);
      

  6.   

    非常感谢各位的回答,但我的意思是要将“HELLO,good,HoW ”一整句转成“Hello,Good,How ”
      

  7.   

    多写一行就可以了
    string strSrc = "Hello,Good,How";
    strSrc.ToLower();
    然后后面的都一样了。
      

  8.   

    string strSrc = "shOw mE tHe moNey.duRing theSe dAys.";
                strSrc = strSrc.ToLower();
                StringBuilder sb = new StringBuilder(strSrc.Length);
                MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?)");
                foreach (Match m in res)
                {
                    sb.AppendFormat("{0:s}{1:s}", m.Groups[1].Value.ToUpper(), m.Groups[2].Value);
                }
                string strDst = sb.ToString();
                MessageBox.Show(strDst);
      

  9.   

    如果你希望包括换行符,就用下面这个正则
    MatchCollection res = Regex.Matches(strSrc, @"(\w)([\w]*\W?[\s]?)");
      

  10.   

    再请问一句StringBuilder和MatchCollection要引用什么的?
      

  11.   

    using System.Text;
    using System.Text.RegularExpressions;
      

  12.   

    using System.Text;
    using System.Text.RegularExpressions;