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

เมธอด Char.IsHighSurrogate(String, Int32) ใน C#


เมธอด Char.IsHighSurrogate() ใน C# บ่งชี้ว่าอ็อบเจ็กต์ Char ที่ตำแหน่งที่ระบุในสตริงเป็นเซอโรเกทสูง (high surrogate) หรือไม่

ไวยากรณ์

public static bool IsHighSurrogate (string str, int index);

str คือสตริง ส่วน index คือตำแหน่งของอักขระที่ต้องการประเมินใน str

ตัวอย่าง

using System; 
public class Demo { 
    public static void Main(){ 
        string str = new String(new char[] { 'k', 'm', 'g', 't', '\uD800' }); 
        bool res = Char.IsHighSurrogate(str, 4); 
        if (res) 
            Console.WriteLine("Contains High Surrogate value!"); 
        else 
            Console.WriteLine("Does not contain High Surrogate value!"); 
    } 
}

ผลลัพธ์

Contains High Surrogate value!

ตัวอย่างที่ 2 (ตำแหน่งที่ไม่ใช่ surrogate)

using System; 
public class Demo { 
    public static void Main(){ 
        string str = new String(new char[] { 'k', 'm', 'g', 't', '\uD800' }); 
        bool res = Char.IsHighSurrogate(str, 2); 
        if (res) 
            Console.WriteLine("Contains High Surrogate value!"); 
        else 
            Console.WriteLine("Does not contain High Surrogate value!"); 
    } 
}

ผลลัพธ์

Does not contain High Surrogate value!