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}攀