我在我的应用程序中嵌入了单声道,但我遇到了单声道的字符串转换问题。
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)) << endl;
}
//...
mono_add_internal_call("SampSharp.GameMode.Natives.Native::Print", (void *)p_Print);
C#代码:
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void Print(string msg);
//...
Print("characters like \u00D6 are working? (should be an O with \" above it)");
输出:
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)”,但是 mono_string_to_utf8 或 _to_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;
}
这可能不是最漂亮的方式,但它确实有效。
关于c# - 单声道并传递 unicode 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24367603/