In my application I want to convert a string that contains character ý, to UTF-8. But its not giving the exact result. I am using WideCharToMultiByte function, it is converting the purticular character to ý.
For Example : Input - "ý" Output - "ý"
Please see the code below..
String strBuffer("ý" );
char *utf8Buffer = (char*)malloc(strBuffer.GetLength()+1);
int utf8bufferLength = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)strBuffer.GetBuffer(strBuffer.GetLength() + 1)),
strBuffer.GetLength(), utf8Buffer, strBuffer.GetLength() * 4,0,0);
Please give your suggestions...
- Binoy Krishna
Unicode codepoint for letter ý, according to this page is 25310 or FD16. UTF-8 representation is 195 189 decimal or C3 BD hexadecimal. These two bytes can be seen as letters ý in your program and/or debugger, but they are UTF-8 numbers, so they are bytes, not letters.
In another words the output and
the codeare fine, and your expectations are wrong. I can't say why are they wrong because you haven't mentioned what exactly were you expecting.EDIT: The code should be improved. See Rudolfs' answer for more info.