Phương thức Char.IsLowSurrogate() trong C# chỉ ra liệu đối tượng Char tại vị trí được chỉ định trong một chuỗi có là surrogate thấp (low surrogate) hay không.
Cú pháp
Dưới đây là cú pháp:
public static bool IsLowSurrogate (string str, int index);
Trong đó, str là một chuỗi, trong khi index là vị trí của ký tự cần đánh giá trong str.
Ví dụ 1
Hãy xem ví dụ sau để triển khai phương thức Char.IsLowSurrogate():
using System;
public class Demo {
public static void Main(){
string str = new String(new char[] { 'k', 'm', 'g', 't', 'j', 'p', '\uDC00' });
bool res = Char.IsLowSurrogate(str, 6);
if (res)
Console.WriteLine("Contains Low Surrogate value!");
else
Console.WriteLine("Does not contain Low Surrogate value!");
}
}
Đầu ra
Chương trình sẽ cho ra kết quả sau:
Contains Low Surrogate value!
Ví dụ 2
Ví dụ khác kiểm tra vị trí không phải surrogate thấp:
using System;
public class Demo {
public static void Main(){
string str = new String(new char[] { 'k', 'm', 'g', 't', 'j', 'p', '\uDC00' });
bool res = Char.IsLowSurrogate(str, 3);
if (res)
Console.WriteLine("Contains Low Surrogate value!");
else
Console.WriteLine("Does not contain Low Surrogate value!");
}
}
Đầu ra
Chương trình sẽ cho ra kết quả sau:
Does not contain Low Surrogate value!