delphi unicode 转 gbk


本文整理自网络,侵删。

 function UniCodetoGBK(S : String):String;
Var
  I,j: Integer;
  str,ps,regmsg: string;
  reg: TPerlRegEx;
begin
  try
    reg := TPerlRegEx.Create(nil);
    regmsg := '\\u[A-Za-z0-9]{4}';
    reg.RegEx := regmsg;
    reg.Subject := s;
    while reg.MatchAgain do
    begin
      ps := reg.MatchedExpression;
      Delete(ps,1,1);
      if (Trim(ps) <> '') and  (Pos('u',ps) = 1) then
      begin
        I := Length(ps);
        while I >=4 do
        begin
          str := WideChar(StrToInt('$'+ps[I-3]+ps[I-2]+ps[I-1]+ps[I]));
          I := I - 4;
        end;
        reg.Replacement := str;
        reg.Replace;
      end;
    end;
    Result := reg.Subject;
    reg.Free;
  except
    reg.Free;
  end;
end;

相关阅读 >>

Delphi获取一个窗口的所有子窗口(包括嵌套)

Delphi 对指定dbgrid进行排序

Delphi 相对路径和绝对路径的转换

Delphi 如何将颜色值转换为html格式?

Delphi xe10.2 firedac 三种连接

Delphi二值图像膨胀算法

Delphi 纯window系统api实现的ssl客户端

Delphi 获取分解时间日期的年月日

Delphi 获取image.picture.data的数据

download 和 http downloader 源码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...