C#转换句子中的第一个字符为大写

using System;

class Demo {
   static String MyApplication(String str) {

      char []val = str.tochararray();

      for (int i = 0; i < str.Length; i++) {
         if (i == 0 && val[i] != ' ' ||
            val[i] != ' ' && val[i - 1] == ' ') {
               if (val[i] >= 'a' && val[i] <= 'z') {
                  val[i] = (char)(val[i] - 'a' + 'A');
               }
            } else if (val[i] >= 'A' && val[i] <= 'Z')
               val[i] = (char)(val[i] + 'a' - 'A');
      }
      String s = new String(val);
      return s;
   }
   public static void Main() {
      String str = Welcome to our website!;
      Console.Write(MyApplication(str));
   }
}

相关文章

c#如何实现添加到列表代码:var list = new&...
c#循环访问字典代码:foreach(var item in m...
using System; namespace OperatorsAppl { class Program ...
using System; class Program { static void Main(string[...
using System; namespace OperatorsAppl { class Program {...
using System; namespace DeclaringConstants { class Pro...