I am trying to read a Unicode string from memory but I am not getting it right. The string I am attempting to read is "EMyExceptÙion" but what I am getting back is "EMyExceptATion" (the Ù turned in to AT). My code is as follows:
I am trying to read a Unicode string from memory but I am not getting it right. The string I am attempting to read is "EMyExceptÙion" but what I am getting back is "EMyExceptATion" (the Ù turned in to AT). My code is as follows:
SetString(LNameStr, PAnsiChar(PByte(LName) + 1), Byte(LName^));
Where LName is of type PAnsiChar to the text, with the first byte being the length of the string (similar to a short string?)
I have tried a few things but I haven't got my head around text conversion :(
SetString(LNameStr, PAnsiChar(PByte(LName) + 1), Byte(LName^));
Where LName is of type PAnsiChar to the text, with the first byte being the length of the string (similar to a short string?)
I have tried a few things but I haven't got my head around text conversion :(
I think that the string in memory is UTF-8 encoded, the length of the string is 13 chars, but there are 14 bytes, so, the special character is encoded using 2 bytes -- normal in UTF-8.
ReplyDeleteso, "the best way" is the way you're doing it, just write a "utility" function to handle this in the future and you're all set.
Looks like it is a UTF8 string with a leading length byte what would be "ShortString" in Delphi. So this should work:
ReplyDeleteLNameStr := UTF8ToString(PShortString(LName)^);
Andreas Hausladen A quick test shows that works perfectly. Nice and simple - thanks :-)
ReplyDelete