Using Delphi XE-5 Firemonkey mobile
I have a string (Path) that looks like this
host domain and node here\\something1\\something2\\something3\\something4\\something5
I need a function that removes each portion with each call. e.g., when call the function the first time, it would remove "\something5" leaving the string as
something1\\something2\\something3\\something4
function CountOccurences( const SubText: string;
const Text: string): Integer;
begin
if (SubText = '') OR (Text = '') OR (Pos(SubText, Text) = 0) then
Result := 0
else
Result := (Length(Text) - Length(StringReplace(Text, SubText, '', [rfReplaceAll]))) div Length(subtext);
end; {Robert Frank}
function IncrementalBackOff(aPath: String): String;
var
I: Integer;
Found: Boolean;
begin
result:= aPath;
if (CountOccurences('\\', result) > 1) then
begin
for I:= Length(result) downto 1 do
begin
if (result[I] <> '\') then
Delete(result, I, 1)
else
begin
Delete(result, I, 1);
Delete(result, I-1, 1);
end;
end;
end;
end;
NOTE: I need to always keep the first section (i.e. never delete '\\something1'
host domain and node here\\something1
So, the function must return the remainng string each time