เมธอด Char.ConvertToUtf32(String, Int32) ใน C# แปลงค่าของอักขระ UTF-16 หรือ Surrogate Pair ที่ตำแหน่งที่ระบุในสตริง ให้เป็น Unicode Code Point
ไวยากรณ์
public static int ConvertToUtf32(string str, int index);
str คือสตริงที่มีอักขระหรือ Surrogate Pair index คือตำแหน่งดัชนีของอักขระหรือ Surrogate Pair ใน str
ตัวอย่างที่ 1
using System;
public class Demo
{
public static void Main()
{
int utf = 0x046;
string str = Char.ConvertFromUtf32(utf);
Console.WriteLine("Final Value = " + str);
int res = Char.ConvertToUtf32(str, 0);
Console.WriteLine("Actual Value = 0x{0:X}", res);
}
}
ผลลัพธ์
Final Value = F
Actual Value = 0x46
ตัวอย่างที่ 2
using System;
public class Demo
{
public static void Main()
{
int utf = 0x057;
string str = Char.ConvertFromUtf32(utf);
Console.WriteLine("Final Value = " + str);
int res = Char.ConvertToUtf32(str, 0);
Console.WriteLine("Actual Value = 0x{0:X}", res);
}
}
ผลลัพธ์
Final Value = W
Actual Value = 0x57
คำอธิบาย: เมธอดนี้ทำงานร่วมกับ Char.ConvertFromUtf32() — ตัวแรกแปลง Code Point เป็นสตริง ตัวหลังแปลงสตริงกลับเป็น Code Point