How to split a line in Inno Setup

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

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

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

Thanks in advance!

+9
source share
2 answers

I was looking for the same thing today ...

This works great on Inno Setup scripts. Insert this snippet inside the script before the procedure / function that calls this split procedure.

You can also change this to a function if you want ...

 procedure Explode(var Dest: TArrayOfString; Text: String; Separator: String); var i, p: Integer; 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; end; procedure Whatever(); var str: String; strArray: TArrayOfString; i: Integer; begin Explode(strArray,str,'.'); for i:=0 to GetArrayLength(strArray)-1 do begin //do something end; end; 

Taken from here

+10
source

For those who prefer the function format, I changed @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; 
+10
source

Source: https://habr.com/ru/post/969780/


All Articles