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

วิธี Char.ConvertToUtf32 (String, Int32) ใน C #


วิธี Char.ConvertToUtf32(String, Int32) ใน C# ใช้เพื่อแปลงค่าของอักขระที่เข้ารหัส UTF-16 หรือคู่ตัวแทนที่ตำแหน่งที่ระบุในสตริงเป็นจุดโค้ด Unicode

ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์ -

public static int ConvertToUtf32 (string str, int index);

ด้านบน str คือสตริงที่มีอักขระหรือตัวแทนเสมือน พารามิเตอร์ดัชนีคือตำแหน่งดัชนีของตัวละครหรือคู่ตัวแทนใน str.

ตัวอย่าง

ให้เราดูตัวอย่างการใช้งานวิธี Char.ConvertToUtf32(String, Int32) -

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

ตัวอย่าง

เรามาดูตัวอย่างอื่นกัน −

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