procedure TForm3.FormCreate(Sender: TObject);
var
st: string;
spos: integer;
begin
st := 'R,123,36';
spos := st.LastIndexOf(',');
caption := st.Substring(spos + 1, st.Length - spos);
end;
var
st: string;
spos: integer;
begin
st := 'R,123,36';
spos := st.LastIndexOf(',');
caption := st.Substring(spos + 1, st.Length - spos);
end;
function Getstr1(S,S1:string):string;
var i,j,L:integer;
begin
Result := '';
L:=Length(S);
J:=0;
for i:=L downto 1 do
if S[i]=S1 then
begin
J:=i;
break;
end;
if J>0 then Result := Copy(S,J+1,L-j);
end;新建 一个工程,测试一下:
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit3.Text:=Getstr1(Edit1.text,Edit2.text);
end;
function Getstr(S,S1:string):string;
var i,j,L:integer;
begin
Result := '';
L:=Length(S);
J:=0;
for i:=1 to L do
if S[i]=S1 then J:=i;
if J>0 then Result := Copy(S,J+1,L-j);
end;
ShowMessage(Copy(s, LastDelimiter(',', s)+1, MAXINT));
还 Reverse 过来,Reverse 回去的。
str.LastIndexOf 再 str.substring 就行,
又简单又明瞭。
var i,j,L:integer;
begin
Result := '';
L:=Length(S);
J:=0;
for i:=L downto 1 do
if S[i]=S1 then
begin
J:=i;
break;
end;
if J>0 then Result := Copy(S,J+1,L-j);
end;
declaration
function LastDelimiter(const Delimiters, S: string): integer;
description
Returns the index of the last occurence in a string of the characters cpecified.
If none of the characters in Delimiters appears in string S, function returns zero. Delimiters cannot be a multibyte string, and we cannot use #0 as one of the delimiters.example
var s : string;
i : integer;s:='http://delphi.about.com';
i:= LastDelimiter('.', s);
//i=20;