ภาพรวม
iswlower() เป็นฟังก์ชันใน C++ STL (header <cwctype> หรือ <wctype.h>) ใช้ตรวจสอบว่า Wide Character เป็นตัวพิมพ์เล็ก (Lowercase) หรือไม่
Syntax
int iswlower(wint_t c);
พารามิเตอร์
c- Wide character ที่ต้องการตรวจสอบ (ชนิดwint_tหรือWEOF)
ค่าที่คืน
- Non-zero (true) - ถ้า c เป็นตัวพิมพ์เล็ก (a-z, รวมถึงตัวอักษรภาษาอื่นใน locale)
- 0 (false) - ถ้าไม่ใช่ตัวพิมพ์เล็ก
ตัวอย่างที่ 1: ตรวจสอบและแปลงตัวพิมพ์เล็กเป็นพิมพ์ใหญ่
#include <stdio.h>
#include <wctype.h>
int main() {
int i = 0;
wchar_t str[] = L"Test String.\n";
wchar_t c;
while (str[i]) {
c = str[i];
if (iswlower(c))
c = towupper(c);
putwchar(c);
i++;
}
return 0;
}
ผลลัพธ์
TEST STRING.
ตัวอย่างที่ 2: ตรวจสอบตัวอักษรเดี่ยว
#include <cwctype>
#include <iostream>
using namespace std;
int main() {
wchar_t c1 = L'a';
wchar_t c2 = L'Z';
wchar_t c3 = L'5';
wcout << L"'a' is lower: " << iswlower(c1) << endl; // 1 (true)
wcout << L"'Z' is lower: " << iswlower(c2) << endl; // 0 (false)
wcout << L"'5' is lower: " << iswlower(c3) << endl; // 0 (false)
return 0;
}
ผลลัพธ์
'a' is lower: 1
'Z' is lower: 0
'5' is lower: 0
คำอธิบายเพิ่มเติม
- ทำงานร่วมกับ
towupper()สำหรับแปลงเป็นพิมพ์ใหญ่ - พึ่งพา Locale ปัจจุบัน (ตั้งค่าด้วย
setlocale()) - สำหรับ ASCII ธรรมดา ใช้
islower()(header<cctype>) แทนได้ - Wide character version เหมาะสำหรับ Unicode/Internationalization