0

I'm receiving a Unicode string from a vendor. I believe they are using UTF-16. I need to convert it to UTF-8 so I can manipulate in my code. I'm using ICU to handle the Unicode. When trying the toUTF8String method, i'm getting characters that show up as upside down question marks "¿¿¿¿¿¿¿¿¿". When trying the extract method, I'm also getting the same output.

#include "unicode/utypes.h"
#include "unicode/ucnv.h"
#include "unicode/ustring.h"
#include "unicode/uchar.h"
#include "unicode/uloc.h"
#include "unicode/unistr.h"

// RawMessage is received as void *
void ReceiveMessage(  RawMessage )
{
    UChar * UCharUnicodeMessage;
    UCharUnicodeMessage = (UChar*)RawMessage;
    UnicodeString in(UcharUnicodeMessage);
    UErrorCode status = U_ZERO_ERROR;
    char dest[in.length()];
    int ln = in.extract(dest,in.length(), NULL, status);
    cout << endl << "***** Unicode String Received from AEM: " << dest << endl;
    string response;
    in.toUTF8String(response);
    cout << "Result of toUTF8String: " << response;
    // Writes this to our database, the 5 and 19 are debug codes
    LogLongMessage("Test", 5, 19, (char*)response.c_str());
}

My database shows the following: ¿¿¿¿¿¿¿¿¿{FaultResponse sequenceNumber="10000001"} {Exception type="System.ArgumentException"} {message}No records where inserted or updated{/message} {detail}System.ArgumentException: No records where inserted or updated{/detail} {/Exception} {/FaultResponse}攀

  • if I use cout, I get the following output: 䵚㌵簶 No records where inserted or updated System.ArgumentException: No records where inserted or updated – DevWannaBe Sep 01 '15 at 18:53
  • 2
    Firstly, it's "Unicode", not "UNICODE". Then, you say you receive a Unicode string from a vendor, but what is the encoding of that string, like e.g. UTF-8? Without knowing that, you can not correctly decode the bytes you received. That said, your code sample is not enough. Firstly, it should be complete, including the bytes that you can't decode. Secondly, please post it inline here. See the posting guideline at https://stackoverflow.com/help/how-to-ask for further info. – Ulrich Eckhardt Sep 01 '15 at 19:00

0 Answers0