How to merge the contents of several variables

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Andy Petrov
Posts: 10
Joined: 17 Mar 2014 14:40

How to merge the contents of several variables

Post 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:

highend
Posts: 14993
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: How to merge the contents of several variables

Post 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;
One of my scripts helped you out? Please donate via Paypal

Andy Petrov
Posts: 10
Joined: 17 Mar 2014 14:40

Re: How to merge the contents of several variables

Post by Andy Petrov »

Cool :appl:

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: How to merge the contents of several variables

Post 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 } .

Post Reply