Để kiểm tra xem một ký tự Unicode có phải là khoảng trắng (whitespace) hay không, ta dùng Char.IsWhiteSpace. Dưới đây là các ví dụ.
Ví dụ 1
using System;
public class Demo {
public static void Main() {
bool res;
char val = ' ';
Console.WriteLine("Value = " + val);
res = Char.IsWhiteSpace(val);
Console.WriteLine("Có phải whitespace? = " + res);
}
}
Kết quả
Value = Có phải whitespace? = True
Ví dụ 2
using System;
public class Demo {
public static void Main() {
bool res;
char val = 'm';
Console.WriteLine("Value = " + val);
res = Char.IsWhiteSpace(val);
Console.WriteLine("Có phải whitespace? = " + res);
}
}
Kết quả
Value = m Có phải whitespace? = False