提取一个字符串左边,或右变或中间的字符串



uses StrUtils;
c:program filesembarcadero ad studio11.0SOURCERTLSYSSystem.SysUtils.pas
 
function Trim(const S: string): string;
function TrimLeft(const S: string): string;
function TrimRight(const S: string): string;


  LeftStr('1234567', 3);
  MidStr('1234567', 3, 2); //Copy
  RightStr('1234567', 3);



uses
    StrUtils;
//返回1个字符在字符串中的位置 * 
procedure TForm1.Button3Click(Sender: TObject);
begin
    ShowMessage(IntToStr( Pos('*',Edit1.Text)  ));
end;
 
//返回*字符串左边的字符
procedure TForm1.Button1Click(Sender: TObject);
begin
   ShowMessage( LeftStr(Edit1.Text, Pos('*',Form1.Edit1.Text) -1 ) );
end;
 
//返回*字符串右边的字符
procedure TForm1.Button2Click(Sender: TObject);
begin
     ShowMessage( RightStr(Edit1.Text, Length(Edit1.text) - Pos('*',Form1.Edit1.Text)  ) );
end;




原文地址:https://www.cnblogs.com/xe2011/p/3165919.html