บทความนี้สาธิตวิธีการตรวจสอบว่าอักขระ Unicode (char) ที่ระบุเป็นตัวพิมพ์เล็ก (lowercase letter) หรือไม่ โดยใช้ method Char.IsLower(char)
ตัวอย่างที่ 1: ตรวจสอบตัวพิมพ์ใหญ่ 'K'
using System;
public class Demo
{
public static void Main()
{
bool res;
char val = 'K';
Console.WriteLine("Value = " + val);
res = Char.IsLower(val);
Console.WriteLine("Is the value a lowercase letter? = " + res);
}
}
ผลลัพธ์
Value = K Is the value a lowercase letter? = False
ตัวอย่างที่ 2: ตรวจสอบตัวพิมพ์เล็ก 'd'
using System;
public class Demo
{
public static void Main()
{
bool res;
char val = 'd';
Console.WriteLine("Value = " + val);
res = Char.IsLower(val);
Console.WriteLine("Is the value a lowercase letter? = " + res);
}
}
ผลลัพธ์
Value = d Is the value a lowercase letter? = True
คำอธิบายเพิ่มเติม
Char.IsLower(char c)คืนค่าtrueถ้าตัวอักษรเป็น lowercase letter ตาม Unicode standard- รวมตัวพิมพ์เล็กทุกภาษา: a-z, à, á, â, ã, ä, å, α, β, γ, あ, ア (ถ้าเป็น lowercase), ฯลฯ
- ไม่นับตัวเลข สัญลักษณ์ whitespace หรือ punctuation
- มี overload
Char.IsLower(string s, int index)สำหรับตรวจสอบในสตริง - Method คู่:
Char.IsUpper(ตัวพิมพ์ใหญ่),Char.ToLower(แปลงเป็นพิมพ์เล็ก),Char.ToUpper(แปลงเป็นพิมพ์ใหญ่) - ใช้ใน validation, parsing, text processing