unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
E: TEdit;
procedure Button1Click(Sender: TObject);
private
S:STRING;
procedure DelSpecStr;
procedure DelStr(DelStr: string);
procedure ClearStr;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DelStr(DelStr:string);
var
PosIndex,LengthCount:integer;
begin
while Pos(DelStr, S) > 0 do
begin
PosIndex:=pos(DelStr, S);
LengthCount:=length(DelStr);
Delete(S,PosIndex,LengthCount);
end;
end;
procedure TForm1.DelSpecStr;
var
PosIndex,LengthCount:integer;
begin
while Pos(',', S) > 0 do
begin
PosIndex:=pos(',', S) - 3;//想删除(31,5)格式
LengthCount:=6;
Delete(S,PosIndex,LengthCount);
end;
end;
//(a+b+c)*2000+d/1000
//S:='(市场A表(29,3)+市场B表(30,3)+市场C表(31,3))*[2000]+市场C表(31,5)/[1000]'
procedure TForm1.ClearStr;
begin
DelStr('市场');
DelStr('表');
DelStr('[');
DelStr(']');
DelSpecStr;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
S:='(市场A表(29,3)+市场B表(30,3)+市场C表(31,3))*[2000]+市场C表(31,5)/[1000]';
ClearStr ;
E.Text:= s;
end;
END.