其他分享
首页 > 其他分享> > SysUtils.StrByteType - 获取字节类型

SysUtils.StrByteType - 获取字节类型

作者:互联网

SysUtils.StrByteType - 获取字节类型

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//利用 StrByteType 做了个函数:
function GetByteType(p: PChar; i: Integer): string;
var
  bt: TMbcsByteType;
begin
  bt := StrByteType(p, i);
  case bt of
    mbSingleByte : Result := 'SingleByte'; {ASCII 字符}
    mbLeadByte   : Result := 'LeadByte';   {双字节字符前半}
    mbTrailByte  : Result := 'TrailByte';  {双字节字符后半}
  end;
end;

//测试:
procedure TForm1.FormCreate(Sender: TObject);
var
  p: PChar;
  i: Integer;
begin
  p := 'abc万一123';

  for i := 0 to Length(p) - 1 do
    Memo1.Lines.Add(GetByteType(p, i));

{显示结果如下:
  SingleByte
  SingleByte
  SingleByte
  LeadByte
  TrailByte
  LeadByte
  TrailByte
  SingleByte
  SingleByte
  SingleByte
}
end;

end.
SysUtils 单元下的公用函数目录

posted on 2008-05-13 14:07  万一  阅读(2462)  评论(1)  编辑  收藏

标签:end,字节,StrByteType,SysUtils,SingleByte,TrailByte
来源: https://blog.51cto.com/u_14617575/2746258