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) - 分析

  • 相关阅读:
    CStrFun
    CUrl
    CCrawl
    CHttp
    类的实例化
    #include文件时用双引号和尖括号的区别
    对于给定的若干个整数,要求计算它们的和!
    汉诺塔问题
    随机数的生成代码
    排列组合C++
  • 原文地址:https://www.cnblogs.com/weijie-liu/p/10138184.html
Copyright © 2011-2022 走看看