Seminko Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
MikahS Posted September 3, 2014 Share Posted September 3, 2014 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 ~ getENVvarsMy 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 More sharing options...
jdelaney Posted September 3, 2014 Share Posted September 3, 2014 (edited) 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 September 3, 2014 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 More sharing options...
JohnOne Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
MikahS Posted September 3, 2014 Share Posted September 3, 2014 I'd go with JohnOne's solution as that was all I was gonna do Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy 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 More sharing options...
jdelaney Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 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 More sharing options...
jdelaney Posted September 3, 2014 Share Posted September 3, 2014 Rather than do the clip get, actually populate a variable with a string, so we can reproduce. 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 More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 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 More sharing options...
Solution MikahS Posted September 3, 2014 Solution Share Posted September 3, 2014 (edited) 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 September 4, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy 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 More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 That's it MikahS! Well done. Link to comment Share on other sites More sharing options...
MikahS Posted September 3, 2014 Share Posted September 3, 2014 Glad to help Seminko Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy 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 More sharing options...
jdelaney Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 (edited) 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 September 3, 2014 by Seminko Link to comment Share on other sites More sharing options...
JohnOne Posted September 3, 2014 Share Posted September 3, 2014 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 More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 (edited) Yes it did. EDIT: well, that -1 was not in the correct place, but except for that it worked. Edited September 3, 2014 by Seminko MikahS 1 Link to comment Share on other sites More sharing options...
kylomas Posted September 3, 2014 Share Posted September 3, 2014 Seminko, Post the actual data and your requirements or those helping you are shooting at a moving target. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 I posted the actual data data above. OK, so I figured out how to StringTrim: Local $WageArraySplit[UBound($WageArray)] For $i = 0 To UBound($WageArray) -1 $WageArray[$i] = StringTrimLeft($WageArray[$i], 19) Next Link to comment Share on other sites More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 (edited) 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 September 3, 2014 by Seminko Link to comment Share on other sites More sharing options...
Seminko Posted September 3, 2014 Author Share Posted September 3, 2014 How to create a new 2D array from two 1D arrays? Local $FinalArray[UBound($NamesArray)] For $i = 0 To UBound($NamesArray) -1 $FinalArray[$i][0] = $NamesArray[$i] $FinalArray[$i][1] = $WageArray[$i] Next _ArrayDisplay($FinalArray) THis doesn't seem to cut it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now