Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

วิธีแปลงตัวอักษรพิมพ์เล็กเป็นพิมพ์ใหญ่ใน C#

หากต้องการแปลงตัวอักษรพิมพ์เล็ก (Lowercase) เป็นพิมพ์ใหญ่ (Uppercase) ใน C# ให้ใช้เมธอด ToUpper()

สมมติว่าคุณมีสตริงดังนี้:

str = "david";

เพื่อแปลงสตริงพิมพ์เล็กด้านบนให้เป็นพิมพ์ใหญ่ ให้ใช้เมธอด ToUpper() ดังนี้:

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

ตัวอย่างโค้ด

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);
            // แปลงเป็นตัวพิมพ์ใหญ่
            Console.WriteLine("Converted to UpperCase : {0}", str.ToUpper());
            Console.ReadLine();
        }
    }
}