function PartitionString(StrV,PrtSymbol: string): TStringList; var iTemp: integer; begin result := TStringList.Create; iTemp := pos(PrtSymbol,StrV); while iTemp>0 do begin if iTemp>1 then result.Append(copy(StrV,1,iTemp-1)); delete(StrV,1,iTemp+length(PrtSymbol)-1); iTemp := pos(PrtSymbol,StrV); end; if Strv<>'' then result.Append(StrV); end; procedure TForm1.Button1Click(Sender: TObject); var BBStr:TStrings; begin BBStr:=PartitionString('sdfsfs[12345678]','['); ShowMessage(BBStr[0]); end;这样就得到你要的sdfsfs了.
上面就得到adfsfs
copy('sdfsfs[12345678]',1,pos('[','sdfsfs[12345678]')-1)
var
iTemp: integer;
begin
result := TStringList.Create;
iTemp := pos(PrtSymbol,StrV);
while iTemp>0 do begin
if iTemp>1 then result.Append(copy(StrV,1,iTemp-1));
delete(StrV,1,iTemp+length(PrtSymbol)-1);
iTemp := pos(PrtSymbol,StrV);
end;
if Strv<>'' then result.Append(StrV);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BBStr:TStrings;
begin
BBStr:=PartitionString('sdfsfs[12345678]','[');
ShowMessage(BBStr[0]);
end;这样就得到你要的sdfsfs了.
copy('sdfsfs[12345678]',1,pos('[','sdfsfs[12345678]')-1