Being a Delphi novice, I have written a simple function, which given a string and a character, returns the indexes of the character's occurrence in the string.
However I am not sure if my implementation is optimal (because I am constantly resizing the dynamic array). Is there a better way to implement this:
type Indexes = array of Integer;
function GetCharacterIndexesInString(inputstring:string; c:char) : Indexes;
var
s : char;
count : integer;
position: integer;
begin
count := 0;
position := 0;
SetLength(result, 0);
for s in inputstring do
begin
if s = c then
begin
count := count+1;
SetLength(result, count);
result[count-1] := position;
end;
position := position+1;
end;
end;