如何使用 C# 將小寫轉換為大寫?


要將小寫轉換為大寫,請在 C# 中使用 ToUpper() 方法。

假設你的字串是 -

str = "david";

要將上述小寫字串轉換為大寫,請使用 ToUpper() 方法 -

Console.WriteLine("Converted to UpperCase : {0}", str.ToUpper());

以下是 C# 中用於轉換字元大小寫的程式碼 -

示例

using System;
using System.Collections.Generic;
using System.Text;

namespace Demo {
   class MyApplication {
      static void Main(string[] args) {

         string str;
         str = "david";
         Console.WriteLine("LowerCase : {0}", str);

         // convert to uppercase
         Console.WriteLine("Converted to UpperCase : {0}", str.ToUpper());
         Console.ReadLine();
      }
   }
}

更新於: 2020-6-21

超過 2K 次瀏覽

開啟你的 職業生涯

完成課程獲取認證

開始
廣告