Jump to content

Keep specific indexes in an array


Seminko
 Share

Go to solution Solved by MikahS,

Recommended Posts

Hey fellas,

I have this:

$Clip = ClipGet()

$FullArrayRaw = StringSplit($Clip, @CRLF, 1)
$FullArraySorted = _ArrayFindAll($FullArrayRaw, "Tarifní mzda")

So basically I have a large block of text which I split up using StringSplit and then do ArrayFindAll.

How do I update the first full array to only cointain indexes returned by ArrayFindAll?

Thanks

Link to comment
Share on other sites

not sure what you mean by "first full array". Do you mean make a new array with only the indexes found by _ArrayFindAll?

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

One way, without that _arrayfindall
 

#include <Array.au3>
Local $array[11]=["a","b","c","d","a","c","a","d","a","a","f"]
For $i = UBound($array) - 1 To 0 Step -1
    If $array[$i] <> "a" Then
        _ArrayDelete($array,$i)
    EndIf
Next
_ArrayDisplay($array)

Output:

[0]|a
[1]|a
[2]|a
[3]|a
[4]|a
 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Probably best just creating a new array, something similar to this...

$FullArrayNotRaw[UBound($FullArraySorted)]
For $i = 0 To UBound($FullArrayNotRaw -1)
    $FullArrayNotRaw[$i] = $FullArraySorted[$i]
Next

$FullArrayRaw = 0

But if you must use same array, then look at ReDim keyword in help file.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I'd go with JohnOne's solution as that was all I was gonna do ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Or this, else send more info:

Local $array[11]=["a","b","c","d","a","c","a","d","a","a","f"]
$aTemp = _ArrayFindAll($array,"a")
For $i = 0 To UBound($aTemp) - 1
    ConsoleWrite($array[$aTemp[$i]] & @CRLF)
Next

output:

a
a
a
a
a

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Tried this but didn't work:

$Clip = ClipGet()

$FullArrayRaw = StringSplit($Clip, @CRLF, 1)
$FullArraySorted = _ArrayFindAll($FullArrayRaw, "Tarifní mzda")

Local $aNewArray[UBound($FullArraySorted)][UBound($FullArrayRaw, 2)]


For $i = 0 To UBound($FullArraySorted) -1 ; Loop through the returned index numbers.
    For $j = 0 To UBound($FullArrayRaw, 2) -1 ; Loop through each of the columns.
        $aNewArray[$i][$j] = $FullArrayRaw [$FullArraySorted[$i]] [$j] ; Populate the new array.
    Next
Next

_ArrayDisplay($aNewArray)
Link to comment
Share on other sites

Let me explain myself better:

Let's say I have this text: CarSpeed 500 TaxDollars 100 JacuzziBills 50 CarSpeed 400 TaxDollars 150 JacuzziBills 30 CarSpeed 100 TaxDollars 170 JacuzziBills 10

Using StringSplit to get an array. Used bad example but trust me, it has to be there. So in the end I get:

CarSpeed

500

TaxDollars

100

JacuzziBills

50

CarSpeed

400

TaxDollars

150

JacuzziBills

30

CarSpeed

100

TaxDollars

170

JacuzziBills

10

Now using ArrayFindAll to find CarSpeed and ArrayFindAll returns the index numbers which would be 1, 7 and 13.

What I need now is take the StringSplit array tell it to only show indexes 1, 7 and 13, which would be this"

CarSpeed

CarSpeed

CarSpeed

BUT, it needs to be plus one, so in the end the array would look like this:

500

400

100

Link to comment
Share on other sites

  • Solution

Hmm.. Maybe

$Clip = ClipGet()

$FullArrayRaw = StringSplit($Clip, @CRLF, 1)
$FullArraySorted = _ArrayFindAll($FullArrayRaw, "Tarifní mzda")

Local $aNewArray[UBound($FullArraySorted)]

For $i = 0 To UBound($FullArraySorted) - 1 ; Loop through the returned index numbers.
    $pos = $FullArraySorted[$i]
    $aNewArray[$i] = $FullArrayRaw[$pos + 1] ; Populate the new array.
Next

_ArrayDisplay($aNewArray)

EDIT: I'm not sure what you are using as a delimiter for StringSplit, but @CRLF will not split the string spaces, only by line.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Glad to help Seminko ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Why so complicated?

#include <Array.au3>
$string = "CarSpeed 500 TaxDollars 100 JacuzziBills 50 CarSpeed 400 TaxDollars 150 JacuzziBills 30 CarSpeed 100 TaxDollars 170 JacuzziBills 10"
$array = StringRegExp($string, "CarSpeed\s(\d+)",3)
_ArrayDisplay($array)
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

That was just a bad example... But lets continue... it's not done by a longshot :-D

 

So now I have two arrays:

$NamesArray = Names and some random stuff:

7250 Michal Balco 1CZ012106 8,00
1902 Ing. Jan Bartusek 1CZ012106 8,00
246 Pavlína Bublíková 1CZ012106 8,00
22434 Ing. Lenka Celerová Smékalová 1CZ012106 8,00
etc. etc. etc.

$WageArray = hourly wage and some random stuff:

Průměr pro náhrady 146,22 11,00 15 000,00
Průměr pro náhrady 182,18 18,00 19 000,00
Průměr pro náhrady 143,24 7,00 15 000,00
Průměr pro náhrady 135,74 17,00 15 000,00
etc. etc. etc.

I need to take these two arrays and somehow strip the stuff I don't want to see.

I want the first array to look like this, so the first few numbers in front and the numbers behind are stripped:

Michal Balco
Ing. Jan Bartusek
Pavlína Bublíková
Ing. Lenka Celerová Smékalová

The second array should just be the first number:

146,22
182,18
143,24
135,74

Is there a way?

 

EDIT: Tried using StringTrim but didn't work:

Local $WageArraySplit[UBound($WageArray)]
For $i = 0 To UBound($WageArray) -1
    StringTrimRight($WageArray[$i], 16)
    StringTrimLeft($WageArray[$i], 19)
Next
Edited by Seminko
Link to comment
Share on other sites

Hmm.. Maybe

$Clip = ClipGet()

$FullArrayRaw = StringSplit($Clip, @CRLF, 1)
$FullArraySorted = _ArrayFindAll($FullArrayRaw, "Tarifní mzda")

Local $aNewArray[UBound($FullArraySorted)]

For $i = 0 To UBound($FullArraySorted -1) ; Loop through the returned index numbers.
    $pos = $FullArraySorted[$i]
    $aNewArray[$i] = $FullArrayRaw[$pos + 1] ; Populate the new array.
Next

_ArrayDisplay($aNewArray)
EDIT: I'm not sure what you are using as a delimiter for StringSplit, but @CRLF will not split the string spaces, only by line.

That's it MikahS! Well done.

Are you seriously trying to say that that code worked?

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Alright, $WageArray solved:

Local $WageArraySpace[UBound($WageArray)]
Local $WageArraySplit[UBound($WageArray)]
For $i = 0 To UBound($WageArray) -1
    $WageArray[$i] = StringTrimLeft($WageArray[$i], 19)
    $WageArraySpace[$i] = StringInStr($WageArray[$i], " ")
    $WageArray[$i] = StringLeft($WageArray[$i], $WageArraySpace[$i])
    MsgBox(1, "", $WageArray[$i])
    ;StringTrimLeft($WageArray[$i], 19)
Next

And $NamesArray solved too:

Local $NamesArraySpace1[UBound($NamesArray)]
Local $NamesArraySpace2[UBound($NamesArray)]
Local $NamesArraySplit[UBound($NamesArray)]
For $i = 0 To UBound($NamesArray) -1
    $NamesArraySpace1[$i] = StringInStr($NamesArray[$i], " ")
    $NamesArray[$i] = StringTrimLeft($NamesArray[$i], $NamesArraySpace1[$i])
    $NamesArraySpace2[$i] = StringInStr($NamesArray[$i], "1CZ")
    $NamesArray[$i] = StringLeft($NamesArray[$i], $NamesArraySpace2[$i]-2)
    MsgBox(1, "", $NamesArray[$i])
    ;StringTrimLeft($WageArray[$i], 19)
Next
Edited by Seminko
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...