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

เมธอด Char.IsWhiteSpace() ใน C#

เมธอด Char.IsWhiteSpace() ใน C# ตรวจสอบว่าอักขระ Unicode ที่ระบุเป็น White Space (ช่องว่าง, แท็บ, บรรทัดใหม่ ฯลฯ) หรือไม่

ไวยากรณ์

public static bool IsWhiteSpace(char ch);

ตัวอย่างที่ 1: ช่องว่าง (Space)

using System;

public class Demo
{
    public static void Main()
    {
        bool res;
        char val = ' ';
        
        Console.WriteLine("Value = " + val);
        res = Char.IsWhiteSpace(val);
        Console.WriteLine("Is the value whitespace? = " + res);
    }
}

ผลลัพธ์

Value = 
Is the value whitespace? = True

ตัวอย่างที่ 2: ตัวอักษรปกติ

using System;

public class Demo
{
    public static void Main()
    {
        bool res;
        char val = 'k';
        
        Console.WriteLine("Value = " + val);
        res = Char.IsWhiteSpace(val);
        Console.WriteLine("Is the value whitespace? = " + res);
    }
}

ผลลัพธ์

Value = k
Is the value whitespace? = False

White Space ที่รองรับ: Space (U+0020), Tab (U+0009), New Line (U+000A), Carriage Return (U+000D), Form Feed (U+000C), Vertical Tab (U+000B) และ Unicode Separator Characters อื่นๆ