Page 1 of 1

How to merge the contents of several variables

Posted: 11 Sep 2015 07:28
by Andy Petrov
Hi, dear members!
Could someone please help me with script?
There are several variables with following contents:

$Var1 = "1|2|3|4....|26"
$Var2 = "a|b|c|d....|z"
$Var3 = "A|B|C|D....|Z"


Easiest way to merge (combine) the contents of variables into variable:
$Var4 = "1aA|2bB|3cC|4dD....|26zZ"

TIA :beer:

Re: How to merge the contents of several variables

Posted: 11 Sep 2015 08:09
by highend
For example:

Code: Select all

    $Var1 = "1|2|3|4|26";
    $Var2 = "a|b|c|d|z";
    $Var3 = "A|B|C|D|Z";

    $Var4 = "";
    while ($i++ < gettoken($Var1, "count", "|")) {
        $Var4 = $Var4 . gettoken($Var1, $i, "|") . gettoken($Var2, $i, "|") . gettoken($Var3, $i, "|") . "|"
    }
    text $Var4;

Re: How to merge the contents of several variables

Posted: 11 Sep 2015 08:37
by Andy Petrov
Cool :appl:

Re: How to merge the contents of several variables

Posted: 11 Sep 2015 10:30
by PeterH
Dependent on further usage of $Var4 you might want to add

Code: Select all

    $Var4 = Substr($Var4, , -1);
behind the loop, i.e. behind the line containing the } .