This function strips and convert (simple) unicode escape sequences from a string.
With those I mean sequences like "u0026" (which is an ampersand).
For example, one of the return strings in the JSON data of a Googleapis call results in:
u003cbu003eLois u0026amp; Clarku003c/bu003e: The New Adventures of Superman
But we'd like to read:
<bu>Lois & Clark</b>: The New Adventures of Superman
This is the simple function I have used - keep in mind that it assumes that the first byte is useless, so in the number sequence "u0026" it will only look at the "26" part (the 2nd byte) which is the hex value of 38 (dec), which in ASCII is an ampersand (see Character Table).
function DecodeUnicodeEscape(const AStr: string): string;
var Nr:integer;
NewStr, OldStr:string;
begin
OldStr:=AStr;
NewStr:='';
while pos('u',OldStr)>0 do
begin
try
Nr:=Hex2Dec(Copy(OldStr, pos('u',OldStr)+2, 4));
NewStr:=NewStr+Copy(OldStr, 0, pos('u',OldStr)-1)+chr(Nr);
oldStr:=Copy(OldStr, pos('u',OldStr)+6, Length(OldStr));
except
// do nothing and be quiet
end;
end;
Result:=NewStr+OldStr;
end;