[Pas2js] store escaped strings
warleyalex
warleyalex at yahoo.com.br
Wed May 16 14:47:25 CEST 2018
Issue: since the pas2js client application should process JSON response,
returned by the web server, I might have issue when I decode such kind of
text: "\u46C0\u4138\u19A0\u342A\u6056\u1020"
solution A:
========
compress_UTF16 := #$46C0#$4138#$19A0#$342A#$6056#$1020;
console.log( decompressFromUTF16(compress_UTF16) ); // --> €13,56
----------------------------------------------------------------------
solution B:
========
(* Unicode to Chinese characters, support for automatic filtering non
Unicode code, namely the non Unicode coding conversion. Converting only
supports standard type beginning with \u *)
function UnicodeToChinese(inputstr: string): string;
var
i:Integer;
index:Integer;
temp,top,last:string;
begin
index:=1;
while index>=0 do
begin
index:= TJSString(inputstr).IndexOf('\u');
if index<0 then
begin
last:= inputstr;
Result:= Result+ last;
Exit;
end;
top:= Copy(inputstr,1,index); //Remove the non UNIC encoding characters
before the characters, such as digital
temp:= Copy(inputstr,index+1,6);//Remove the code, including the \u,
such as \u4e3f
Delete(temp,1,2);
Delete(inputstr,1,index+6);
result:= Result+ top+ WideChar( StrToInt('$'+ temp)) ;
end;
end;
-----------------
compress_UTF16 := '\u46C0\u4138\u19A0\u342A\u6056\u1020';
console.log( decompressFromUTF16( UnicodeToChinese(compress_UTF16) ) ); //
--> €13,56
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list