Char.IsHighSurrogate() วิธีการใน C# ระบุว่าวัตถุ Char ที่ตำแหน่งที่ระบุในสตริงเป็นตัวแทนที่สูงหรือไม่
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
public static bool IsHighSurrogate (string str, int index);
ด้านบน str คือสตริง ในขณะที่ดัชนีคือตำแหน่งของอักขระที่จะประเมินใน str
ตัวอย่าง
ให้เราดูตัวอย่างการใช้วิธี Char.IsHighSurrogate() -
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!
ตัวอย่าง
เรามาดูตัวอย่างอื่นกัน −
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!