Jump to content
Sign in to follow this  

How to transform array and to get indexes of array elements?

Recommended Posts



I have three arrays

$F1 = StringSplit(“24|42|03|24|24|03|42”, “|”)

$F2 = StringSplit( “11|10|60” , “|”)

$F3 = StringSplit( “42|24|03” , “|”)

How can I do the following:

1. To transform an array $F1 into array $R2 = “02|01|03|02|02|03|01” – every value here is the index in $F3 of $F1 value

I.e. $F1[1] = 24 – it is the second element in $F3=> $R[1] = 01. …. $F1[6] =03 – it is the third element in $F3 => $R[6] = 03

How to make a new array?

2. To substitute every value in $F1 according to following key 24=11, 42=10, 03=60 (an array will be longer, thats why IF is not comfortable)

The outcome should be $R2 = “10|11|60|10|10|60|11”

Thank you!

Share this post

Link to post
Share on other sites

Hello Leanna

see my solutions:


$F1 = StringSplit("24|42|03|24|24|03|42", "|")
$F2 = StringSplit( "11|10|60","|")
$F3 = StringSplit( "42|24|03","|")

Dim $R1[$F1[0] +1]
For $i = 1 To $F1[0]
    For $j = 1 To $F3[0]
        If $F1[$i] = $F3[$j] Then
            $R1[$i] = StringFormat("%02s", $j)


$string = "24|42|03|24|24|03|42|"
StringReplace($string, "24|", "11|")
StringReplace($string, "42|", "10|")
StringReplace($string, "03|", "60|")
$F1 = StringSplit(StringTrimRight($string, 1), "|")

As you can see I solved the second Problem without any Arrays affected.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post

Link to post
Share on other sites


Thank you very much! You helped me a lot!

Works perfect.

Edited by Leanna

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.