How to split a string in Inno Setup

srikanth1267 picture srikanth1267 · May 23, 2014 · Viewed 9.2k times · Source

How can I split a string in Inno Setup?
Is there any special function in Inno Setup to split the string?

I want to get the following from the string '11.2.0.16':

tokens: array of string = ('11', '0', '2', '16');

Thanks in advance!

Answer

timyha picture timyha · Jun 20, 2016

For anyone who prefers the function format, I have modified @cezarlamann's answer:

function StrSplit(Text: String; Separator: String): TArrayOfString;
var
  i, p: Integer;
  Dest: TArrayOfString; 
begin
  i := 0;
  repeat
    SetArrayLength(Dest, i+1);
    p := Pos(Separator,Text);
    if p > 0 then begin
      Dest[i] := Copy(Text, 1, p-1);
      Text := Copy(Text, p + Length(Separator), Length(Text));
      i := i + 1;
    end else begin
      Dest[i] := Text;
      Text := '';
    end;
  until Length(Text)=0;
  Result := Dest
end;