我正在玩erlang和分布式数据库Mnesia。在Erlang处理.Net UTF-8字符串
我面临的第一个问题之一是erlang和.Net UTF-8字符串的'int list'字符串之间不兼容。
有什么好的转换库吗?
感谢
我正在玩erlang和分布式数据库Mnesia。在Erlang处理.Net UTF-8字符串
我面临的第一个问题之一是erlang和.Net UTF-8字符串的'int list'字符串之间不兼容。
有什么好的转换库吗?
感谢
新R13B发布二郎对Unicode的更好的支持。
新的Unicode模块记录在here中,并且在EEP 10(Erlang Enhancement Proposal 10)中描述了实现的Unicode支持。
据我所看到的,二郎使用UTF32,所以使用System.Text.Encoding.UTF32可能做的伎俩来获取列表中的整数,那么你需要创建这些列表。虽然没有测试过。
以下摘录可以帮助(它创建的unicode int
S的应该符合预期二郎神列表中的人的数组):
public static int[] GetIntsForString(string source) {
byte[] data = System.Text.Encoding.UTF32.GetBytes(source);
int[] result = new int[source.Length];
for (int i = 0; i < source.Length; i++) {
result[i] = BitConverter.ToInt32(data, i*4);
}
return result;
}
你有任何例子吗? – 2009-04-24 13:31:35
.NET字符串在内存中本质上是UTF-16,而不是UTF-8。如果您省略编码,则UTF-8是大多数API使用的默认编码,仅此而已。 – 2009-04-24 13:24:56