分享

delphi 取得汉字编码及区位码

 独孤求财 2012-03-20

delphi 取得汉字编码及区位码

时间:2011-5-26来源:yang 作者: peng点击: 12次

Caption := IntToStr(Ord(‘A‘));
 Caption := IntToStr(Ord(WideString(‘的‘)[1]));

//====================================================
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  cMinGBCByte = 161;                          //最小国标字节
  cMaxGBCByte = 254;                          //最大国标字节

function StrToGBC(mStr: string): string; { 返回汉字所对应的区位码 }
begin
  if Length(mStr) = 2 then
    Result := FormatFloat(‘00‘, Ord(mStr[1]) - cMinGBCByte + 1)
        + FormatFloat(‘00‘, Ord(mStr[2]) - cMinGBCByte + 1)
  else Result := ‘‘;
end; { StrToGBC }

function GBCToStr(mStr: string): string; { 返回区位码所对应的汉字 }
var
  I, J: Integer;
begin
  I := StrToIntDef(mStr, 0);
  J := I mod 100;
  I := I div 100;
  I := I + cMinGBCByte - 1;
  J := J + cMinGBCByte - 1;
  Result := Chr(I) + Chr(J)
end; { GBCToStr }

procedure TForm1.Button1Click(Sender: TObject);
begin
  Caption := GBCToStr(Edit1.Text)
end;

end.  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多