从网络上收集的一些经常会用到的字符串处理函数(基于delphi实现)
1.Get the Position of a string, starting at the end

Code
function LastPos(SearchStr, Str: string): Integer;
var
i: Integer;
TempStr: string;
begin
Result := Pos(SearchStr, Str);
if Result = 0 then Exit;
if (Length(Str) > 0) and (Length(SearchStr) > 0) then
begin
for i := Length(Str) + Length(SearchStr) - 1 downto Result do
begin
TempStr := Copy(Str, i, Length(Str));
if Pos(SearchStr, TempStr) > 0 then
begin
Result := i;
break;
end;
end;
end;
end;
function LastPos(SubStr, S: string): Integer;
var
Found, Len, Pos: integer;
begin
Pos := Length(S);
Len := Length(SubStr);
Found := 0;
while (Pos > 0) and (Found = 0) do
begin
if Copy(S, Pos, Len) = SubStr then
Found := Pos;
Dec(Pos);
end;
LastPos := Found;
end;
2.Search for the next occurence of a string from a certain Position

Code
function NextPos(SearchStr, Str: string; Position: Integer): Integer;
begin
Delete(Str, 1, Position - 1);
Result := Pos(SearchStr, upperCase(Str));
if Result = 0 then Exit;
if (Length(Str) > 0) and (Length(SearchStr) > 0) then
Result := Result + Position + 1;
end;
3.Get the number of characters from a certain Position to the string to be searched

Code
function NextPosRel(SearchStr, Str: string; Position: Integer): Integer;
begin
Delete(Str, 1, Position - 1);
Result := Pos(SearchStr, UpperCase(Str)) - 1;
end;