现在的位置: 首页 > 综合 > 正文

SysUtils.StrEnd、SysUtils.StrLen

2011年04月24日 ⁄ 综合 ⁄ 共 665字 ⁄ 字号 评论关闭
StrEnd 获取 PChar 串未指针; StrLen 获取 PChar 串长度.

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}

//StrEnd:
procedure TForm1.Button1Click(Sender: TObject);
var
  p: PChar;
  str: string;
begin
  str := '123456789';
  p := StrEnd(PChar(str));
  ShowMessage(p-3); {789}
end;

//StrLen:
procedure TForm1.Button2Click(Sender: TObject);
var
  p: PChar;
  i: Integer;
begin
  p := '123456789';

  i := StrLen(p);
  ShowMessage(IntToStr(i)); {9}

  i := Length(p);
  ShowMessage(IntToStr(i)); {9}
end;

end.

SysUtils 单元下的公用函数目录


抱歉!评论已关闭.