procedure TForm2.Button1Click(Sender: TObject); var sString,dString:String; i,ePos,Counter:integer; begin sString:=edit1.Text; Counter:=0; for i:=Length(sString) downto 1 do begin if copy(sString,i,1)='*' then begin Counter:=Counter+1; if Counter=2 then begin ePos:=i; end; end; end; dString:=Copy(sString,1,ePos); showmessage(dString); end;
function GetMySubStr(aString: string; SepChar: string): string; var i: Integer; StrLen: Integer; Num: Integer; j:array of integer; begin StrLen:=Length(aString); Num := 0; setlength(j,strlen); for i:= 1 to StrLen do if Copy(aString,i,1) = SepChar then begin j[Num]:=i; Num:=Num + 1; end; result:=copy(astring,1,j[Num-2]); end;调用 showmessage(GetMySubStr(Edit1.text,'*'));
function AMethod(s: string): string; var a: PChar; begin Result := Copy(s, 0, Length(s) - 1); a := StrRScan(PChar(Result), '*'); if a <> nil then a^ := #0; end;procedure TForm1.Button3Click(Sender: TObject); begin Edit3.Text := AMethod(Edit2.Text); end;
chechy(chechy) 兄方法不错,我改了改,更符合题意,嘻嘻 var a: PChar; begin Result := Copy(s, 0, Length(s) - 1); a := StrRScan(PChar(Result), '*'); if a <> nil then begin inc(a); a^ := #0; end; end;
var
sString,dString:String;
i,ePos,Counter:integer;
begin
sString:=edit1.Text;
Counter:=0;
for i:=Length(sString) downto 1 do
begin
if copy(sString,i,1)='*' then
begin
Counter:=Counter+1;
if Counter=2 then
begin
ePos:=i;
end;
end;
end;
dString:=Copy(sString,1,ePos);
showmessage(dString);
end;
var
i: Integer;
StrLen: Integer;
Num: Integer;
j:array of integer;
begin
StrLen:=Length(aString);
Num := 0;
setlength(j,strlen);
for i:= 1 to StrLen do
if Copy(aString,i,1) = SepChar then
begin
j[Num]:=i;
Num:=Num + 1;
end;
result:=copy(astring,1,j[Num-2]);
end;调用
showmessage(GetMySubStr(Edit1.text,'*'));
var
a: PChar;
begin
Result := Copy(s, 0, Length(s) - 1);
a := StrRScan(PChar(Result), '*');
if a <> nil then
a^ := #0;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
Edit3.Text := AMethod(Edit2.Text);
end;
var
a: PChar;
begin
Result := Copy(s, 0, Length(s) - 1);
a := StrRScan(PChar(Result), '*');
if a <> nil then begin
inc(a);
a^ := #0;
end;
end;