使瑞典字符正常工作的正确编码

问题描述 投票:0回答:0

这是我的应用程序的架构。

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 将适用于我。

c# c++ utf-8 ascii encode
© www.soinside.com 2019 - 2024. All rights reserved.