zoukankan      html  css  js  c++  java
  • 汉字与区位码(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) - 分析

  • 相关阅读:
    android system.img
    ab压力测试和CC预防
    ubuntu工具积累
    ViewManager
    PopupWindow
    singleton注意
    java byte[]生成
    java有符号无符号的转换
    C#垃圾回收Finalize 和Dispose的理解
    Silverlight 获取汉字拼音首字母
  • 原文地址:https://www.cnblogs.com/del/p/1336444.html
Copyright © 2011-2022 走看看