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

โปรแกรม C# ตรวจสอบว่าตัวอักษรเป็น whitespace หรือไม่

ใช้ char.IsWhiteSpace(char) ตรวจสอบว่าตัวอักษรเป็น Whitespace (Space, Tab, Newline, Carriage Return, Form Feed, Vertical Tab) หรือไม่

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

using System;

class Demo
{
    static void Main()
    {
        char c = ' ';
        if (char.IsWhiteSpace(c))
        {
            Console.WriteLine("Whitespace character!");
        }
    }
}

ผลลัพธ์

Whitespace character!

เมธอดที่เกี่ยวข้อง: char.IsLetter, char.IsDigit, char.IsLetterOrDigit, char.IsControl, char.IsPunctuation เป็นต้น