• Delphi实现js中的escape()编码和unescape()解码


    相关资料:

    http://www.it588.cn/softdev/2019-05-06/603.html

    方法一:

    引入单元:

    uses

    ActiveX,

    ComObj;

    实例调用:

    //javascript中的escape()函数的delphi实现
    function Escape(s: string): string;
    var
    sc: OleVariant;
    begin
    ActiveX.CoInitialize(nil);
    try
    sc := CreateOleObject('MSScriptControl.ScriptControl.1');
    sc.Language := 'javascript';
    Result := sc.Eval('escape(''' + s + ''')');
    except
    Result := '';
    end;
    ActiveX.CoUninitialize;
    end;

    //javascript中的unescape()函数的delphi实现
    function UnEscape(s: string): string;
    var
    sc: OleVariant;
    begin
    ActiveX.CoInitialize(nil);
    try
    sc := CreateOleObject('MSScriptControl.ScriptControl.1');
    sc.Language := 'javascript';
    s := StringReplace(s, '/u', '%u', [rfReplaceAll, rfIgnoreCase]); //'u' 一些格式转换,根据自己需要处理
    Result := sc.Eval('unescape(''' + s + ''')');
    except
    end;
    ActiveX.CoUninitialize;
    end;

    方法二:

    相关资料:

    https://blog.csdn.net/cc001100/article/details/81015182

    http://www.delphitop.com/html/zifuchuan/4728.html

    http://www.tansoo.cn/?p=736

     1 function AnsiToUnicode(Str: ansistring): string;
     2 var
     3   s: ansistring;
     4   i: integer;
     5   j, k: string[2];
     6   a: array [1..1000] of ansichar;
     7 begin
     8   s := '';
     9   StringToWideChar(Str, @(a[1]), 500);
    10   i := 1;
    11   while ((a[i] <> #0) or (a[i+1] <> #0)) do
    12   begin
    13     j := IntToHex(Integer(a[i]), 2);
    14     k := IntToHex(Integer(a[i+1]), 2);
    15     s := s + 'u'+ k + j;
    16     i := i + 2;
    17   end;
    18   Result := s;
    19 end;
    20 
    21 function UnicodeToAnsi(aSubUnicode: string): string;
    22 var
    23   tmpLen, iCount: Integer;
    24   tmpWS: WideString;
    25 begin
    26   tmpWS := '';
    27   iCount := 1;
    28   tmpLen := Length(aSubUnicode);
    29   while iCount <= tmpLen do
    30     try
    31       if (Copy(aSubUnicode, iCount, 1) = '')
    32         and (Copy(aSubUnicode, iCount, 2) = 'u') then
    33       begin
    34         tmpWS := tmpWS
    35           + WideChar(StrToInt('$' + Copy(aSubUnicode, iCount + 2, 4)));
    36         iCount := iCount + 6;
    37       end
    38       else
    39       begin
    40         tmpWS := tmpWS + Copy(aSubUnicode, iCount, 1);
    41         iCount := iCount + 1;
    42       end;
    43     except
    44     end;
    45   Result := tmpWS;
    46 end;
  • 相关阅读:
    struts 简单配置运用做一个简单的注册
    hibernate 锁 (转)
    Hibernate 缓存机制(转)
    解决Hibernate:could not initialize proxy
    el 表达式用法(转)
    自动生成Hibernate框架结构
    封装hibernate 初始化类 方便调用 (静态单例模式)
    构建hibernate 框架实现增删改查功能
    JSON 与 对象 、集合 之间的转换(转)
    Ajax 引擎 传输数据的方法
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/12620494.html
Copyright © 2020-2023  润新知