I'm playing a bit with erlang and the distributed db Mnesia.
我正在玩erlang和分布式db Mnesia。
One of the first problem I'm facing is the incompatibilty beetween the 'int list' strings of erlang and .Net UTF-8 strings.
我面临的第一个问题之一是erlang和.Net UTF-8字符串的'int list'字符串之间的不兼容性。
Is there any good conversion library?
有没有好的转换库?
Thanks
2 个解决方案
#1
The new R13B release of Erlang has better support for unicode.
Erlang的新R13B版本对unicode有更好的支持。
The new Unicode module is documented here and the Unicode support implemented is described in the EEP 10 (Erlang Enhancement Proposal 10).
这里记录了新的Unicode模块,并且在EEP 10(Erlang Enhancement Proposal 10)中描述了实现的Unicode支持。
#2
As far as I have seen, erlang uses UTF32, so using System.Text.Encoding.UTF32 might do the trick to get the ints for the list, then you need to create the list from those. Not tested though.
据我所知,erlang使用UTF32,因此使用System.Text.Encoding.UTF32可能会获得列表的整数,然后您需要从那些创建列表。虽然没经过测试
The following snippet may help (it creates an array of unicode int
s which should match the ones expected for the erlang list):
以下代码段可能会有所帮助(它会创建一个unicode int数组,该数组应与erlang列表的预期值相匹配):
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;
}
#1
The new R13B release of Erlang has better support for unicode.
Erlang的新R13B版本对unicode有更好的支持。
The new Unicode module is documented here and the Unicode support implemented is described in the EEP 10 (Erlang Enhancement Proposal 10).
这里记录了新的Unicode模块,并且在EEP 10(Erlang Enhancement Proposal 10)中描述了实现的Unicode支持。
#2
As far as I have seen, erlang uses UTF32, so using System.Text.Encoding.UTF32 might do the trick to get the ints for the list, then you need to create the list from those. Not tested though.
据我所知,erlang使用UTF32,因此使用System.Text.Encoding.UTF32可能会获得列表的整数,然后您需要从那些创建列表。虽然没经过测试
The following snippet may help (it creates an array of unicode int
s which should match the ones expected for the erlang list):
以下代码段可能会有所帮助(它会创建一个unicode int数组,该数组应与erlang列表的预期值相匹配):
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;
}