上記の方法では誤りのある数値を復号します
「9519、80、19、85、1991、1991、191、21、001、1、001、191、44、89、88、00、01、001、0077、B、55、1」 以下の方法を用いると、このような問題は発生しません。
- function reconvert(str){
- str = str.replace(/(\\u)(\w{1,4})/gi,function($0){
- return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{1,4})/g,"$2")),16)));
- });
- str = str.replace(/(&#x)(\w{1,4});/gi,function($0){
- return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{1,4})(%3B)/g,"$2"),16));
- });
- str = str.replace(/(&#)(\d{1,6});/gi,function($0){
- return String.fromCharCode(parseInt(escape($0).replace(/(%26%23)(\d{1,6})(%3B)/g,"$2")));
- });
- return str;
- }
コードをコピーします
|