Janilabo Posted May 22, 2012 Share Posted May 22, 2012 Returns all positions of S in STR. Example included. PosAll [scar]function PosAll(s, str: string): TIntArray; var sL, strL, o, p, r: Integer; begin sL := Length(s); strL := Length(str); if (sL > strL) then Exit; SetLength(Result, strL); repeat p := PosEx(s, str, (o + 1)); if (p > 0) then begin Result[r] := p; o := p; Inc®; end; until (p <= 0); SetLength(Result, r); end; var s, str: string; TIA: TIntArray; h, i: Integer; begin ClearDebug; str := '|||| PosAll() Test ||| *** ||| Should work pretty well. ||||'; s := '||'; TIA := PosAll(s, str); h := High(TIA); if (h < 0) then Exit; str := '"' + s + '" positions in str: '; for i := 0 to h do if (i < h) then str := str + IntToStr(TIA) + ', ' else str := str + IntToStr(TIA) + '.'; WriteLn(str); SetLength(TIA, 0); end.[/scar] Quote Link to comment Share on other sites More sharing options...