⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delphiucs2gb.txt

📁 Delphi函数源代码,GB和UCS2互转换
💻 TXT
字号:
function Ucs2ToGB2312(const InValue: string): string;
var
  I, asc: Integer;
begin
  Result := '';
  for I := 1 to Length(InValue) div 2 do
  begin
    asc :=Ord(InValue[I *2 -1]);
    if asc<>$20 then
      Result := Result + WideChar(StrToInt('$' + IntToHex(Ord(asc), 2) + IntToHex(Ord(InValue[I *2]), 2)))
    else
      Result := Result + Chr(StrToInt('$' +IntToHex(Ord(InValue[I *2]),2)));
  end;
end;

function GB2312ToUcs2(const InValue: string): string;
var
  i : Integer;
  ucs4 : UCS4String;
  ucs2 : String;
begin
  Result := '';
  ucs4 := WideStringToUCS4String(InValue);
  for i:=Low(ucs4) to High(ucs4)-1 do
  begin
    ucs2 := IntToHex(ucs4[i],4);
    if ucs4[i]<$20 then //$7F
      Result :=Result + ' ' + Chr(StrToInt('$'+ucs2))
    else
      Result := Result + Chr(StrToInt('$'+Copy(ucs2,1,2))) + Chr(StrToInt('$'+Copy(ucs2,3,2)));
  end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -