2006. november 9., csütörtök
How to implement the RPos
Problem/Question/Abstract:
Sometime Pos is not enough, because you need to find the position of the first character of a sub string in a string from the end of that string. There's the solution.
Answer:
function RPos(Substr: string; S: string): Integer;
var
i: Integer;
begin
Result := 0;
if ((Length(S) > 0) and (Length(Substr) > 0)) then
if (Length(S) >= Length(Substr)) then
for i:= (Length(S) - Length(Substr)) downto 1 do
if (Copy(S, i, Length(Substr)) = Substr) then
begin
Result := i;
Exit;
end;
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése