[Lazarus] JSon stream to unicode?
Leonardo M. Ramé
l.rame at griensu.com
Sat Nov 13 03:31:13 CET 2010
On 2010-11-13 00:43:40 +0100, Michael Fuchs wrote:
> Leonardo M. Ramé schrieb:
> > Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse
> > library) containing Unicode data and I need to show it in a Lazarus
> > form. How can I convert it to look correctly on screen?.
> >
> > Example:
> >
> > The string "Leonardo Ramé" is shown as "Leonardo Ram\u009".
> >
>
>
> I had the same problem and use now the following function for decoding:
>
> function DecodeUnicodeEscapes(EscapedString: String): String;
> var
> FoundPos: LongInt;
> HexCode: String;
> DecodedChars: String;
> begin
> Result := EscapedString;
> FoundPos := Pos('\u', Result);
> while (FoundPos <> 0) and (FoundPos < Length(Result) - 4) do begin
> HexCode := Copy(Result, FoundPos + 2, 4);
> DecodedChars := WideChar(Hex2Dec(HexCode));
> Result := AnsiReplaceStr(Result, '\u' + HexCode,
> UTF8Encode(DecodedChars));
> FoundPos := Pos('\u', Result);
> end;
> end;
>
>
> hth
> Michael
>
Thanks Michael, I'll try that.
--
Leonardo M. Ramé
http://leonardorame.blogspot.com
More information about the Lazarus
mailing list