需要引用strUtils
unit Unit1;
interface
uses
Windows, StrUtils,Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s,s1,s2: string;
begin
s:=‘0001000200030004‘;
s1:= LeftStr(s,4);
s2:= RightStr(s,4);
ShowMessage(‘s1 leftstr‘+ s1 + ‘ ‘+ ‘ s2 rightstr‘ + s2);
end;
结果显示
LEFTSTR(‘中国1‘,4) 结果为‘中国‘
MIDSTR(‘12314‘,2,4) 结果为‘2314‘
一点问题也没有,非常正确.