_arraysort by stringmid?

Recommended Posts

Hi guys,

*another* problem to solve! Should be a quickie tho...

for a given array e.g.

\$array[0] = "abc 001 abc"

\$array[1] = "def 003 abc"

\$array[2] = "abc 002 zxy"

\$array[3] = "345 005 abc"

\$array[4] = "abc 004 abc"

is it possible to sort the array by the middle 3 numbers (e.g. via stringmid(\$array[x],5,3))

so the array is sorted to:

\$array[0] = "abc 001 abc"

\$array[1] = "abc 002 zxy"

\$array[2] = "def 003 abc"

\$array[3] = "abc 004 abc"

\$array[4] = "345 005 abc"

(note middle numbers are now in order)

???

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Share on other sites
• Developers

I would temporarily add the primary key at the start of the array values... something like:

```#include<array.au3>
Dim \$array[5]
\$array[0] = "abc 001 abc"
\$array[1] = "def 003 abc"
\$array[2] = "abc 002 zxy"
\$array[3] = "345 005 abc"
\$array[4] = "abc 004 abc"
For \$x = 0 to UBound(\$array)-1
\$array[\$x] = StringMid(\$array[\$x],5,3) & \$array[\$x]
Next
_ArraySort(\$array)
For \$x = 0 to UBound(\$array)-1
\$array[\$x] = StringMid(\$array[\$x],4)
Next
_ArrayDisplay(\$array)```
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files

Live for the present,
Dream of the future,
Learn from the past.

Share on other sites

I would teporarely add the primary key at the start of the array values... something like:

```#include<array.au3>
Dim \$array[5]
\$array[0] = "abc 001 abc"
\$array[1] = "def 003 abc"
\$array[2] = "abc 002 zxy"
\$array[3] = "345 005 abc"
\$array[4] = "abc 004 abc"
For \$x = 0 to UBound(\$array)-1
\$array[\$x] = StringMid(\$array[\$x],5,3) & \$array[\$x]
Next
_ArraySort(\$array)
For \$x = 0 to UBound(\$array)-1
\$array[\$x] = StringMid(\$array[\$x],4)
Next
_ArrayDisplay(\$array)```

Genius!! thank you!!!

You know one of the things I find most amazing about autoit (I've only been programming for a few months), is that there could be countless ways of achieving what you want a program to do, and it is possible that one way of doing something could be 30 - 40 lines of script but it gets the job done...

...then someone with a touch of innovation can do the same thing in 14 elegant lines of script!!!

How long before I pick up that sort of innovation!!!?!?!??!?! ha ha

Thanks again!!!

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

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