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

## Recommended Posts

Hello!

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 on other sites

Hello Leanna

see my solutions:

1:

```\$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)
ExitLoop
EndIf
Next
Next
_ArrayDisplay(\$R1)```

2:

```\$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 on other sites

hannes08

Thank you very much! You helped me a lot!

Works perfect.

Edited by Leanna

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...