# Array Position

## Recommended Posts

Ok, I am in logic hell, and I know I'm over complicating it.

I have 2 arrays.

```Local \$a_original[9] = [8, 0, 1, 2, 3, 4, 5, 6, 7]
Local \$a_switch[5] = [4, 0, 2, 5, 7]; could be any number of elements from 0 - 7```

I pass an index to place \$a_switch after

`Local \$i_switch_at = 4`

The final array needs to look like:

`Local \$a_final[9] = [8, 1, 3, 4, 0, 2, 5, 7, 6]`

[0] is the number of index elements in the array.

Anyone have a simple solution to achieve this?

Edit:

Tired of messing with it... this looks like it may have it:

```#include <array.au3>

Local \$a_original[9] = [8, 0, 1, 2, 3, 4, 5, 6, 7]
Local \$a_switch[5] = [4, 0, 2, 5, 7]
Local \$i_switch_at = 4
;~ Local \$a_final[9] = [8, 1, 3, 4, 0, 2, 5, 7, 6]
Local \$s_string = ","

For \$i = 1 To \$a_switch[0]
\$s_string &= \$a_switch[\$i] & ","
Next

Local \$s_out_put = ""
For \$i = 1 To \$a_original[0]
If StringInStr(\$s_string, "," & \$a_original[\$i] & ",") = 0 Then
\$s_out_put &= \$a_original[\$i] & ","
EndIf
If \$i = \$i_switch_at + 1 Then \$s_out_put &= "|"
Next

Local \$a_split = StringSplit(StringTrimRight(\$s_out_put, 1), "|")
For \$i = 1 To \$a_switch[0]
\$a_split[1] &= \$a_switch[\$i] & ","
Next

Local \$s_final_out = \$a_split[1] & \$a_split[2]
Local \$a_final = StringSplit(\$s_final_out, ",")

_ArrayDisplay(\$a_final)
ConsoleWrite(\$s_final_out & @CRLF)```
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

I'm thinking you might want to try something like this:

```Local \$s_string = ","
For \$i = 1 To \$a_add[0]
Next

For \$i = 1 To \$av_array[0]
If StringInStr(\$s_string, "," & \$av_array[\$i] & ",") Then ContinueLoop
\$i_count += 1
\$a_temp_delete[\$i_count] = \$av_array[\$i]
Next

Local \$a_temp_insert = \$a_temp_delete
For \$i = \$a_add[0] To 1 Step -1
Next```

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

Automate input type=file (Related)

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

##### Share on other sites

I'm thinking you might want to try something like this:

```Local \$s_string = ","
For \$i = 1 To \$a_add[0]
Next

For \$i = 1 To \$av_array[0]
If StringInStr(\$s_string, "," & \$av_array[\$i] & ",") Then ContinueLoop
\$i_count += 1
\$a_temp_delete[\$i_count] = \$av_array[\$i]
Next

Local \$a_temp_insert = \$a_temp_delete
For \$i = \$a_add[0] To 1 Step -1
NextoÝ÷ Ø6¥{ú®¢×©ä°6¥y«2¢é'£    èµ§ÚÑx8¦Â§!Ú'ßÛd!£  +bëjh(x-¢¯zÚyÚ"­YéíÂ+a²¶§X¤zØb±«­¢+Ø\$%1½°ÀÌØíÍ}ÍÑÉ¥¹ôÅÕ½Ðì°ÅÕ½Ðì(\$%½ÈÀÌØí¤ôÄQ¼ÀÌØí}lÁt(\$\$\$ÀÌØíÍ}ÍÑÉ¥¹µÀìôÀÌØí}lÀÌØí¥tµÀìÅÕ½Ðì°ÅÕ½Ðì(\$%9áÐ(\$\$(\$%1½°ÀÌØí}ÑµÁ}±ÑmU ½Õ¹ ÀÌØíÙ}ÉÉä¤´ÀÌØí}lÁut(\$%½ÈÀÌØí¤ôÄQ¼ÀÌØíÙ}ÉÉålÁt(\$\$%%MÑÉ¥¹%¹MÑÈ ÀÌØíÍ}ÍÑÉ¥¹°ÅÕ½Ðì°ÅÕ½ÐìµÀìÀÌØíÙ}ÉÉålÀÌØí¥tµÀìÅÕ½Ðì°ÅÕ½Ðì¤Q¡¸
½¹Ñ¥¹Õ1½½À(\$\$\$ÀÌØí¥}½Õ¹Ð¬ôÄ(\$\$\$ÀÌØí}ÑµÁ}±ÑlÀÌØí¥}½Õ¹ÑtôÀÌØíÙ}ÉÉålÀÌØí¥t(\$%9áÐ((\$%1½°ÀÌØí}ÑµÁ}¥¹ÍÉÑmU   ½Õ¹ ÀÌØí}ÑµÁ}±Ñ¤¬ÀÌØí}lÁutìôÀÌØí}ÑµÁ}±Ñ(\$%½ÈÀÌØí¤ôÄQ¼ÀÌØí¥}±½Õ¹´Ä(\$\$\$ÀÌØí}ÑµÁ}¥¹ÍÉÑlÀÌØí¥tôÀÌØí}ÑµÁ}±ÑlÀÌØí¥t(\$%9áÐ(\$\$(\$%½ÈÀÌØí¤ôÄQ¼ÀÌØí}lÁt(\$\$\$ÀÌØí}ÑµÁ}¥¹ÍÉÑlÀÌØí¤¬ÀÌØí¥}±½Õ¹´ÅtôÀÌØí}lÀÌØí¥t(\$%9áÐ(\$\$(\$%½ÈÀÌØí¤ôÀÌØí¥}±½Õ¹¬ÀÌØí}lÁtQ¼U  ½Õ¹ ÀÌØí}ÑµÁ}¥¹ÍÉÐ¤´Ä(\$\$\$ÀÌØí}ÑµÁ}¥¹ÍÉÑlÀÌØí¥tôÀÌØíÙ}ÉÉålÀÌØí¥t(\$%9áÐ```

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

## Create an account

Register a new account