<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nsis.sourceforge.io/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Explode</id>
	<title>Explode - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://nsis.sourceforge.io/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Explode"/>
	<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=Explode&amp;action=history"/>
	<updated>2026-04-09T05:13:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=Explode&amp;diff=12702&amp;oldid=prev</id>
		<title>Cryonyx at 08:40, 10 July 2007</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=Explode&amp;diff=12702&amp;oldid=prev"/>
		<updated>2007-07-10T08:40:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{PageAuthor|cryonyx}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Version:&amp;#039;&amp;#039;&amp;#039; 1.0&lt;br /&gt;
The function splits passed string on the basis of the separator and pushes results to stack. The last value pushed is the length of the array.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Explode&amp;#039;&amp;#039;&amp;#039; accepts two parameters: separator and string to split. After processing the data it pushes to the stack values in the direct order and then pushes the count of array items stored there. This means that if you have string &amp;quot;Col 1,Col 2,Col 3&amp;quot; and a separator &amp;quot;,&amp;quot;, then your stack will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
[0]    3&lt;br /&gt;
[1]    Col 1&lt;br /&gt;
[2]    Col 2&lt;br /&gt;
[3]    Col 3&lt;br /&gt;
[4]    ...&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
${Explode} &amp;quot;Length&amp;quot; &amp;quot;Separator&amp;quot; &amp;quot;String&amp;quot;&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
Push &amp;quot;Separator&amp;quot;&lt;br /&gt;
Push &amp;quot;String&amp;quot;&lt;br /&gt;
Call Explode&lt;br /&gt;
Pop  &amp;quot;Length&amp;quot;&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Parameters ===&lt;br /&gt;
&lt;br /&gt;
;Length&lt;br /&gt;
:Variable in which the length of the returned array is stored.&lt;br /&gt;
&lt;br /&gt;
;Separator&lt;br /&gt;
:String, which delimiters parts of the array in the string&lt;br /&gt;
&lt;br /&gt;
;String&lt;br /&gt;
:String to be splitted&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
    ${Explode}  $0  &amp;quot;,&amp;quot; &amp;quot;Col 0,Col 1,Col 2&amp;quot;&lt;br /&gt;
    MessageBox  MB_OK &amp;quot;$0 elements in array&amp;quot;&lt;br /&gt;
    ${For} $1 1 $0&lt;br /&gt;
        Pop $2&lt;br /&gt;
        MessageBox MB_OK &amp;quot;Element #$1: $2&amp;quot;&lt;br /&gt;
    ${Next}&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Function code (requires [[LogicLib header file]]) ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!define Explode &amp;quot;!insertmacro Explode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!macro  Explode Length  Separator   String&lt;br /&gt;
    Push    `${Separator}`&lt;br /&gt;
    Push    `${String}`&lt;br /&gt;
    Call    Explode&lt;br /&gt;
    Pop     `${Length}`&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
Function Explode&lt;br /&gt;
  ; Initialize variables&lt;br /&gt;
  Var /GLOBAL explString&lt;br /&gt;
  Var /GLOBAL explSeparator&lt;br /&gt;
  Var /GLOBAL explStrLen&lt;br /&gt;
  Var /GLOBAL explSepLen&lt;br /&gt;
  Var /GLOBAL explOffset&lt;br /&gt;
  Var /GLOBAL explTmp&lt;br /&gt;
  Var /GLOBAL explTmp2&lt;br /&gt;
  Var /GLOBAL explTmp3&lt;br /&gt;
  Var /GLOBAL explArrCount&lt;br /&gt;
  &lt;br /&gt;
  ; Get input from user&lt;br /&gt;
  Pop $explString&lt;br /&gt;
  Pop $explSeparator&lt;br /&gt;
  &lt;br /&gt;
  ; Calculates initial values&lt;br /&gt;
  StrLen $explStrLen $explString&lt;br /&gt;
  StrLen $explSepLen $explSeparator&lt;br /&gt;
  StrCpy $explArrCount 1&lt;br /&gt;
&lt;br /&gt;
  ${If}   $explStrLen &amp;lt;= 1          ;   If we got a single character&lt;br /&gt;
  ${OrIf} $explSepLen &amp;gt; $explStrLen ;   or separator is larger than the string,&lt;br /&gt;
    Push    $explString             ;   then we return initial string with no change&lt;br /&gt;
    Push    1                       ;   and set array&amp;#039;s length to 1&lt;br /&gt;
    Return&lt;br /&gt;
  ${EndIf}&lt;br /&gt;
  &lt;br /&gt;
  ; Set offset to the last symbol of the string&lt;br /&gt;
  StrCpy $explOffset $explStrLen&lt;br /&gt;
  IntOp  $explOffset $explOffset - 1&lt;br /&gt;
  &lt;br /&gt;
  ; Clear temp string to exclude the possibility of appearance of occasional data&lt;br /&gt;
  StrCpy $explTmp   &amp;quot;&amp;quot;&lt;br /&gt;
  StrCpy $explTmp2  &amp;quot;&amp;quot;&lt;br /&gt;
  StrCpy $explTmp3  &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
  ; Loop until the offset becomes negative&lt;br /&gt;
  ${Do}&lt;br /&gt;
    ;   If offset becomes negative, it is time to leave the function&lt;br /&gt;
    ${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}&lt;br /&gt;
    &lt;br /&gt;
    ;   Remove everything before and after the searched part (&amp;quot;TempStr&amp;quot;)&lt;br /&gt;
    StrCpy $explTmp $explString $explSepLen $explOffset&lt;br /&gt;
 &lt;br /&gt;
    ${If} $explTmp == $explSeparator&lt;br /&gt;
        ;   Calculating offset to start copy from&lt;br /&gt;
        IntOp   $explTmp2 $explOffset + $explSepLen ;   Offset equals to the current offset plus length of separator&lt;br /&gt;
        StrCpy  $explTmp3 $explString &amp;quot;&amp;quot; $explTmp2&lt;br /&gt;
        &lt;br /&gt;
        Push    $explTmp3                           ;   Throwing array item to the stack&lt;br /&gt;
        IntOp   $explArrCount $explArrCount + 1     ;   Increasing array&amp;#039;s counter&lt;br /&gt;
        &lt;br /&gt;
        StrCpy  $explString $explString $explOffset 0   ;   Cutting all characters beginning with the separator entry&lt;br /&gt;
        StrLen  $explStrLen $explString&lt;br /&gt;
    ${EndIf}&lt;br /&gt;
    &lt;br /&gt;
    ${If} $explOffset = 0                       ;   If the beginning of the line met and there is no separator,&lt;br /&gt;
                                                ;   copying the rest of the string&lt;br /&gt;
        ${If} $explSeparator == &amp;quot;&amp;quot;              ;   Fix for the empty separator&lt;br /&gt;
            IntOp   $explArrCount   $explArrCount - 1&lt;br /&gt;
        ${Else}&lt;br /&gt;
            Push    $explString&lt;br /&gt;
        ${EndIf}&lt;br /&gt;
    ${EndIf}&lt;br /&gt;
    &lt;br /&gt;
    IntOp   $explOffset $explOffset - 1&lt;br /&gt;
  ${Loop}&lt;br /&gt;
&lt;br /&gt;
  Push $explArrCount&lt;br /&gt;
FunctionEnd&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Versions History ==&lt;br /&gt;
&lt;br /&gt;
;1.0&lt;br /&gt;
:Creates array in stack, splitting passed string. No support for limitation of items to output&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Version 1.0 - [[User:cryonyx|cryonyx]]&lt;br /&gt;
&lt;br /&gt;
[[Category:String Functions]]&lt;br /&gt;
[[Category:Array Functions]]&lt;/div&gt;</summary>
		<author><name>Cryonyx</name></author>
	</entry>
</feed>