Janilabo Posted May 22, 2012 Share Posted May 22, 2012 Returns all strings between S1 and S2 of STR. Exaple included. AllBetween [scar]function AllBetween(s1, s2, str: string): TStringArray; var s1L, s2L, sL, r, sp, start, fp, finish: Integer; tmp: string; begin sL := Length(str); s1L := Length(s1); s2L := Length(s2); if (sL > 0) and (s1L > 0) and (s2L > 0) then if (sL >= (s1L + s2L)) then begin SetLength(Result, (sL * (sL - (s1L + s2L)))); repeat sp := PosEx(s1, str, (start + 1)); if (sp > 0) then begin start := sp; finish := ((start + s1L) - 1); repeat fp := PosEx(s2, str, (finish + 1)); if fp > 0 then begin finish := fp; tmp := Copy(str, (start + s1L), (finish - (start + s1L))); if tmp <> '' then begin Result[r] := tmp; Inc®; tmp := ''; end; end; until (fp <= 0); end; until (sp <= 0); end; SetLength(Result, r); end; var str: string; TSA: TStringArray; h, i: Integer; begin ClearDebug; str := '***AllBetween()**Test***'; TSA := AllBetween('*', '*', str); h := High(TSA); if (h < 0) then Exit; for i := 0 to h do WriteLn('TSA[' + IntToStr(i) + ']: ' + TSA); SetLength(TSA, 0); end.[/scar] Quote Link to comment Share on other sites More sharing options...