漢字與區位碼(1) - 轉換函數


先上轉換函數:


 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{查漢字區位碼}
function Str2GB(const s: AnsiString): string;
const
  G = 160;
begin
  Result := Format('%d%d', [Ord(s[1])-G, Ord(s[2])-G]);
end;

{通過區位碼查漢字}
function GB2Str(const n: Word): string;
const
  G = 160;
begin
  Result := string(AnsiChar(n div 100 + G) + AnsiChar(n mod 100 + G));
end;


{測試}
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GB2Str(4582)); {萬}
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage(Str2GB('萬')); {4582}
end;

end.


獲取區位碼表: 准備個 Memo 接收(注意使用了上面的函數)


var
  i,j: Byte;
  s: string;
begin
  s := '';
  for i := 1 to 94 do
  begin
    for j := 1 to 94 do
      s := Format('%s %s', [s, GB2Str(i*100 + j)]);
    Memo1.Lines.Add(s);
    s := '';
  end;
end;


漢字與區位碼(2) - 分析


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM