Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Expand(trgt_pos: Integer; s1, s2, str: string; includeTags: Boolean): string;
- var
- l, p, start, finish, s1L, s2L, e: Integer;
- tmp: string;
- begin
- Result := '';
- l := Length(str);
- s1L := Length(s1);
- s2L := Length(s2);
- if ((s1L <= l) and (s2L <= l) and (trgt_pos <= l) and (trgt_pos >= 1)) then
- begin
- if includeTags then
- begin
- s1L := 0;
- e := s2L;
- s2L := 0;
- end;
- finish := PosEx(s2, str, trgt_pos);
- if ((finish < 1) or (finish = trgt_pos)) then
- Exit;
- tmp := Copy(str, 1, trgt_pos);
- repeat
- p := PosEx(s1, tmp, (p + 1));
- if (p > 0) then
- start := p;
- until (p <= 0);
- if ((start <> trgt_pos) and (start > 0) and (finish > 0) and (start < finish)) then
- Result := Copy(str, (start + s1L), (((finish - start) - S2L) + e));
- tmp := '';
- end;
- end;
- var
- str, tmp: string;
- id, id_pos: Integer;
- begin
- ClearDebug;
- str := '{* Lets do this... {* function Expand() *} It is... Magical! *}';
- WriteLn('ExpandEx(): "' + Expand(Pos('Expand', str), '{* ', ' *}', str, True) + '" [tags included]');
- WriteLn('ExpandEx(): "' + Expand(Pos('Expand', str), '{* ', ' *}', str, False) + '" [without tags]');
- end.
Advertisement
Add Comment
Please, Sign In to add comment