Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MultiBetweenEx(str, s1, s2: string; method: Integer): array of string;
- var
- s1L, s2L, strL, s, o, n, e, r: Integer;
- begin
- strL := Length(str);
- s1L := Length(s1);
- if (strL <= Length(s1 + s2)) or (s1L < 1) or (Length(s2) < 1) or not InRange(method, 0, 3) then
- Exit;
- SetLength(Result, (strL - (s1L + s2L)));
- case method of
- 0: repeat
- n := PosEx(s1, str, (n + 1));
- if (n < 1) then
- Break;
- e := PosEx(s2, str, (n + 1));
- if (e < 1) then
- Break;
- repeat
- o := n;
- n := PosEx(s1, str, (n + 1));
- until (n >= e) or (n < 1);
- n := o;
- Result[r] := Between(s1, s2, Copy(str, n, (s1L + (e + s2L))));
- if (Result[r] <> '') then
- Inc(r);
- until (e < 1) or (n < 1);
- 1..3: repeat
- case method of
- 1, 2: s := PosEx(s1, str, (e + 1));
- 3: s := PosEx(s1, str, (s + 1));
- end;
- e := PosEx(s2, str, (s + 1));
- if (s < 1) or (e < 1) then
- Break;
- Result[r] := Copy(str, (s + s1L), (e - (s + s1L)));
- if (Result[r] <> '') then
- Inc(r)
- else
- if (method = 1) then
- e := ((s + s1L) - 1);
- until (s < 1) or (e < 1);
- end;
- SetLength(Result, r);
- end;
- var
- m, h, i: Integer;
- TSA: array of string;
- Text: string;
- begin
- ClearDebug;
- for m := 0 to 3 do
- begin
- WriteLn('*** METHOD ' + IntToStr(m) + ' ***');
- WriteLn('MultiBetweenEx() Test1:');
- Text := '<tag>test1<tag>..<tag>test2dgtsgtsgdsgs<tag>....<tag>test3<tag>.....<tag>test4<tag>.....';
- TSA := MultiBetweenEx(Text, '<tag>', '<tag>', m);
- h := High(TSA);
- for i := 0 to h do
- WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA[i]);
- WriteLn('');
- SetLength(TSA, 0);
- WriteLn('MultiBetweenEx() Test2:');
- Text := '<tag>test1</tag>....<tag>test2dgtsgtsgdsgs</tag>....<tag>test3</tag>.....<tag>test4</tag>.....';
- TSA := MultiBetweenEx(Text, '<tag>', '</tag>', m);
- h := High(TSA);
- for i := 0 to h do
- WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA[i]);
- WriteLn('');
- SetLength(TSA, 0);
- WriteLn('MultiBetweenEx() Test3:');
- Text := '||*|*||<|<||[|]||>|>||*|*||';
- TSA := MultiBetweenEx(Text, '|', '|', m);
- h := High(TSA);
- for i := 0 to h do
- WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA[i]);
- SetLength(TSA, 0);
- WriteLn('*** METHOD ' + IntToStr(m) + ' ***');
- if (m < 4) then
- WriteLn('');
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment