提问人:Nitheesh Kedlaya 提问时间:2/23/2023 更新时间:2/23/2023 访问量:166
正确编码以使瑞典字符正常工作
Proper encoding for Swedish characters to work
问:
这是我的应用程序的架构。
Client1(C# code)
SendMsg()
{
String input = "Östen"
//Send to server Decode API
}
Server (C++ code )
Decode(string messageToSend)
{
int size = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, messageToSend.c_str(),
messageToSend.length(), nullptr, 0);
std::wstring utf16_str(size, '\0');
MultiByteToWideChar(CP_ACP, MB_COMPOSITE, messageToSend.c_str(),
messageToSend.length(), &utf16_str[0], size);
int utf8_size = WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),
utf16_str.length(), nullptr, 0,
nullptr, nullptr);
std::string utf8_str(utf8_size, '\0');
WideCharToMultiByte(CP_UTF8, 0, utf16_str.c_str(),
utf16_str.length(), &utf8_str[0], utf8_size,
nullptr, nullptr);
}
Client 2 (C# code )
ShowMsg()
{
//Display msg which is received from server
//Here it displays as Östen instead of Östen
}
正如我在输出中所说,输出应该是正确的瑞典语字符。 很少有其他客户端使用相同的服务器 API 调用,并且它对他们有用,我觉得他们使用正确的编码。 所以我不想修改服务器代码。
想要对 Client1 代码进行更改。 即使用正确的编码。 我尝试了UTF-8,htmlencoding。W1252 .他们都不适合我。
任何人都可以帮助我在客户端中使用哪种编码。因此,相同的服务器 API 将对我有用。
答: 暂无答案
下一个:无法解码字节数组中的文本
评论
'Östen'.encode( 'utf-8').decode( 'cp1252')
Östen