C# mono和传递unicode字符串
我将mono嵌入到我的一个应用程序中,但我对mono的字符串转换有问题 C++代码:C# mono和传递unicode字符串,c#,c++,unicode,mono,C#,C++,Unicode,Mono,我将mono嵌入到我的一个应用程序中,但我对mono的字符串转换有问题 C++代码: static inline void p_Print(MonoString *str) { cout << "UTF8: " << mono_string_to_utf8(str) << endl; wcout << "UTF16: " << ((wchar_t*)mono_string_to_utf16(str)) <<
static inline void p_Print(MonoString *str) {
cout << "UTF8: " << mono_string_to_utf8(str) << endl;
wcout << "UTF16: " << ((wchar_t*)mono_string_to_utf16(str)) << endl;
}
//...
mono_add_internal_call("SampSharp.GameMode.Natives.Native::Print", (void *)p_Print);
输出:
UTF8: characters like Ö are working? (should be an O with " above it)
UTF16: characters like Í are working? (should be an O with " above it)
正如您所看到的,输出不完全是它应该打印的,它应该打印“像Ö这样的字符正在工作”(应该是一个带“在上面”的O),但是单字符字符串到utf8或到utf16都不做它应该做的事情
如何解决此问题?解决方法如下:
string mono_string_to_string(MonoString *str)
{
mono_unichar2 *chl = mono_string_chars(str);
string out("");
for (int i = 0; i < mono_string_length(str); i++) {
out += chl[i];
}
return out;
}
string mono\u string\u to\u string(MonoString*str)
{
mono_unichar2*chl=mono_string_chars(str);
用(“”)号填列;
对于(int i=0;i
这可能不是最漂亮的方法,但它很有效。您使用的是什么操作系统,您是从命令行界面运行程序的吗?如果Windows上的cmd.exe恰好是,它不支持unicode。您可以尝试将其上的代码页设置为支持您试图打印的符号的代码页,但可以肯定的是,它支持redirect输出到文本文件中,应该会给出正确的结果(好吧,除非问题在其他地方;))感谢您提供有关控制台的信息。但是我在其他地方也使用了_to_utf8,并在其他地方显示它。当我发送到显示器时(不是在控制台的其他地方)U900D6直接从C++中显示正确的字符,但是从C/单/单声道中调用相同的函数├ā.那一定是_to_utf8的问题。@ikkentim它在Linux中对我有效(如果你愿意,我可以给你一个例子),我打赌你有编码问题。你应该找出编译时使用的编码以及“显示”的编码“事情需要时间。”古斯曼,你能给我举个例子吗?也许我以后可以在自己的代码中找到问题。
string mono_string_to_string(MonoString *str)
{
mono_unichar2 *chl = mono_string_chars(str);
string out("");
for (int i = 0; i < mono_string_length(str); i++) {
out += chl[i];
}
return out;
}