C#中的Char.ConvertToUtf32(String,Int32)方法用于将字符串中指定位置的UTF-16编码字符或代理对的值转换为Unicode代码点。
以下是语法-
public static int ConvertToUtf32 (string str, int index);
在上面,str是包含字符或代理对的字符串。index参数是字符或代理对在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