Jump to content

Recommended Posts

#Include <Array.au3>
#include <Constants.au3>

$s = FileRead("2.txt")

Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended

Next
_ArraySort($w, 1, 0, 0, 1)
_ArrayDisplay($w)

i have this script that returns 3 columns  

 

i need to copy the  Col 0 and Col 1 as text to paste on notepad or excel

you will have to create a "copy" button if possible

array.au3 2.txt

Link to post
Share on other sites
19 minutes ago, vinnyMS said:

you will have to create a "copy" button if possible

Not me, YOU, will have to create a copy button. This addition to your code will write the required output which you can then open in notepad or import into excel. Or, you can insert it into your clipboard buffer using ClipPut().

$sOut = ""
For $i = 0 To UBound($w) - 1
  $sOut = $sOut & $w[$i][0] & @TAB & $w[$i][1] & @CRLF
Next
FileWrite("2out.txt", $sOut)

 

Phil Seakins

Link to post
Share on other sites
Posted (edited)

Just use _DebugArrayDisplay instead of _ArrayDisplay, you'll find 2 copy buttons that will copy the results in the Clipboard

DebugArrayDisplay.png.bf614eb96ca589e1566039938dc6e3b2.png

* Results are whole columns if no row is selected.
* If you select some lines, then only the selected lines are copied
* If your display retrieved for example 10 columns and you want to copy only columns 0-1, then use the array range param. (3rd param) to display only 2 columns

_DebugArrayDisplay($w, "Title", "|0:1")

* If you don't want the "Row column" to appear, just add the correct 4th param.

_DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

This will do it :

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>

$s = FileRead("2.txt")

Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended

Next
_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w)

; _DebugArrayDisplay($w, "Title", "|0:1")
; _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

Edit: While I was writing this, DanP2 just said it too :)

Edited by pixelsearch
Link to post
Share on other sites
46 minutes ago, vinnyMS said:

It lists "5679" only

You really should make more of an effort to provide a detailed description of your issue. As it is, I have no idea what "it" is.

FWIW, I'm not experiencing any issues when running this short example --

#include <Debug.au3>

; Create 1D array to display
Local $aArray_1D[5] = [-5679.01, -5679.011, -5679.012, -5679.013, -5679.014]

_DebugArrayDisplay($aArray_1D, "1D display")

 

Link to post
Share on other sites
56 minutes ago, Danp2 said:

You really should make more of an effort to provide a detailed description of your issue. As it is, I have no idea what "it" is.

FWIW, I'm not experiencing any issues when running this short example --

#include <Debug.au3>

; Create 1D array to display
Local $aArray_1D[5] = [-5679.01, -5679.011, -5679.012, -5679.013, -5679.014]

_DebugArrayDisplay($aArray_1D, "1D display")

 

i have attached the text file

Screenshot_6.png

2.txt

Link to post
Share on other sites
53 minutes ago, vinnyMS said:

need exact numbers with operator and decimal on the Array display

There is a problem with your regexp but I can't help you with that. Outside my area of expertise.

#include <File.au3>
;..
;..
_FileReadToArray("2.txt", $s, 0, @TAB)

This will give you an array that is undistorted

Phil Seakins

Link to post
Share on other sites

This does something like you want, but unsure what you want to do with the duplicates. You can delete them in a loop if required.

$as1 = ''
_FileReadToArray("2.txt", $as1, 0, @TAB)
Local $s[UBound($as1, 2)] ; for 1D array
;Local $s[UBound($as1, 2)][2] ; for 2D
For $i = 0 To UBound($as1, 2) - 1
  ;$s[$i][0] = $as1[0][$i] ; 2D
  ;$s[$i][1] = $i ; 2D
  $s[$i] = $as1[0][$i] ; 1D
Next
$as1 = ""
_ArraySort($s) ; dups NOT deleted or counted
_ArrayDisplay($s)

 

Phil Seakins

Link to post
Share on other sites

Hello, I would have done it like this :

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>

$s = FileRead("2.txt")

;~ Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
Local $w = StringRegExp($s, '(?s)(\-?\.?\d+\b)(?!.*\1\b)', 3)
_DebugArrayDisplay($w, "1")

_ArrayColInsert($w, 1)
_DebugArrayDisplay($w, "2")

For $i = 0 to UBound($w)-1
    ;~ StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
    StringRegExpReplace($s, '(?s)' & StringReplace($w[$i][0], ".", "\.") , "")
    $w[$i][1] = @extended
Next
_DebugArrayDisplay($w, "3")

_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w, "4")

 

Link to post
Share on other sites
3 hours ago, vinnyMS said:

Hopefully the regexp can be fixed

Where did the regex even come from?

Just do this:

#include <Array.au3>
#include <Debug.au3>

Local $aNums = StringSplit(FileRead("2.txt"), @TAB, 2)

_ArraySort($aNums)
_ArrayAdd($aNums, "")
Local $aNumsO[Ubound($aNums)][2]

Local $iMatches=1, $m=0

For $n = 1 To Ubound($aNums)-1
   If $aNums[$n] = $aNums[$n-1] Then
     $iMatches+=1
   Else
     $aNumsO[$m][0]=$aNums[$n-1]
     $aNumsO[$m][1]=$iMatches
     $iMatches=1
     $m+=1
   EndIf
Next

$aNumsO[$m][0]=$aNums[$n-1]
$aNumsO[$m][1]=$iMatches

Redim $aNumsO[$m][2]

_ArraySort($aNumsO, 1, 0, 0, 1)
_DebugArrayDisplay($aNumsO)

 

Code hard, but don’t hard code...

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DannyJ
      I have a dataset like this, (a strubg)
      Username: User1 Type: Admin RegDate: 1999 Username: User2 Type: User RegDate: 2000 How to make a 2 dimensional array that I can display with _ArrayDisplay?
      This would be a perfect 2D array to represent my data:
      Username           Tpye RegDate User1              Admin 1999 User2              User 2000   If you run this Powershell this powershell command, you can get this dataset that I am talking about:
      Get-LocalUser | Select * With this code you can try it to read into a string:
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion $sCommand = "powershell.exe Get-LocalUser | Select *" Local $iPid = Run($sCommand, @WorkingDir , @SW_SHOW , $STDOUT_CHILD) ProcessWaitClose($iPid) Local $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput) How can I correctly split $sOutput into a 2D array (with the above mentioned layout) that I can display and I work with?
    • By kovlad
      My solution is to write nested arrays without copying.
      The problem was described hier.
       
      Function:
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayNestedSet ; Description ...: Assigns a value to an element of a nested 1D array. ; Syntax ........: _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue) ; Parameters ....: $aArray - an array of arrays. ; $vIndex - an index or 1d-array of indexes; ; a size if $vValue not defined (zero to delete). ; $vValue - a value (create, resize or delete if not defined). ; ; Return values .: on success - 1 ; @extended - nesting level of operation ; on failure - 0 ; @extended - nesting level of error ; @error = 1 - invalid array ; @error = 2 - invalid index ; Author ........: ; Modified ......: kovlad ; Remarks .......: ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/185638-assign-a-value-to-an-array-in-array-element/ ; https://www.autoitscript.com/trac/autoit/ticket/3515?replyto=description ; Example .......: Yes ; =============================================================================================================================== Func _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue = Default) Local $extended = @extended + 1 If IsArray($vIndex) Then If UBound($vIndex, 0) <> 1 Then _ Return SetError(2, $extended) If UBound($vIndex) > 1 Then If UBound($aArray, 0) <> 1 Then _ Return SetError(1, $extended) ; keep index for this array Local $i = $vIndex[0] If $i < 0 Or UBound($aArray) <= $i Then _ Return SetError(2, $extended) ; delete index of this array _ArrayDelete($vIndex, 0) ; recursive function call Local $return = _ArrayNestedSet($aArray[$i], $vIndex, $vValue) If @error Then Return SetError(@error, @extended + 1, 0) Else Return SetExtended(@extended + 1, 1) EndIf Else $vIndex = $vIndex[0] EndIf EndIf If $vValue = Default Then If $vIndex < 0 Then _ Return SetError(2, $extended) If $vIndex = 0 Then ; delete array and free memory $aArray = 0 Return SetExtended($extended, 1) EndIf If UBound($aArray, 0) = 1 Then ; resize array keeping data ReDim $aArray[$vIndex] Return SetExtended($extended, 1) Else ; create new nested array Local $aTmp[$vIndex] $aArray = $aTmp Return SetExtended($extended, 1) EndIf Else If UBound($aArray) <= $vIndex Then _ Return SetError(2, $extended + 1) ; set value of array entry $aArray[$vIndex] = $vValue Return SetExtended($extended, 1) EndIf EndFunc  
      Examples:
      ; write value to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 1st nested array" & @CRLF) Local $aTmp1[4] = [1,2,3,4] _ArrayDisplay($aTmp1, "$aTmp1") Local $aArray[2] = [$aTmp1] ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 3, 14) = " & _ArrayNestedSet($aArray[0], 3, 14) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; resize 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 1st nested array" & @CRLF) ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 8) = " & _ArrayNestedSet($aArray[0], 8) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; write array to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write array to 1st nested array" & @CRLF) Local $aTmp11[4] = [11,12,13,14] _ArrayDisplay($aTmp11, "$aTmp11") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 2, $aTmp11) = " & _ArrayNestedSet($aArray[0], 2, $aTmp11) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; write value to 2nd nested array using index array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 2nd nested array using index array" & @CRLF) Local $aIndex1[2] = [2,3] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1, 140) = " & _ArrayNestedSet($aArray[0], $aIndex1, 140) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; resize 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 2nd nested array" & @CRLF) Local $aIndex1[2] = [2,8] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1) = " & _ArrayNestedSet($aArray[0], $aIndex1) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; create new 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : create new 3rd nested array" & @CRLF) Local $aIndex2[3] = [2,7,6] _ArrayDisplay($aIndex2, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex2) = " & _ArrayNestedSet($aArray[0], $aIndex2) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay((($aArray[0])[2])[7], ")($aArray[0])[2])[7]") ; delete 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 3rd nested array" & @CRLF) Local $aIndex3[3] = [2,7,0] _ArrayDisplay($aIndex3, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex3) = " & _ArrayNestedSet($aArray[0], $aIndex3) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray((($aArray[0])[2])[7]) = " & IsArray((($aArray[0])[2])[7]) & @CRLF & @CRLF) ; write 0 in 1st nested array to delete the 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write 0 in 1st nested array to delete the 2nd nested array" & @CRLF) Local $aIndex4[1] = [2] _ArrayDisplay($aIndex4, "$aIndex4") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex4, 0) = " & _ArrayNestedSet($aArray[0], $aIndex4, 0) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray(($aArray[0])[2]) = " & IsArray(($aArray[0])[2]) & @CRLF & @CRLF) ; delete 1st nested array (same as '$aArray[0] = 0') ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 1st nested array (same as '$aArray[0] = 0')" & @CRLF) Local $aIndex5[1] = [0] _ArrayDisplay($aIndex5, "$aIndex5") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex5) = " & _ArrayNestedSet($aArray[0], $aIndex5) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray($aArray[0]) = " & IsArray($aArray[0]) & @CRLF & @CRLF)  
    • By DannyJ
      $sCommands1 = 'powershell.exe Get-ChildItem' $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2) $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) ConsoleWrite("$sOutput") ConsoleWrite($sOutput) ConsoleWrite(@CRLF) $aOutput = stringsplit($sOutput ,@LF , 2) For $i=0 To  UBound($aOutput) - 1 Step 1     ConsoleWrite($aOutput[$i]) Next The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.
      I have already read some forum answers here, and I have already tried these commands:
       
      Are there any way to use the $aOutput variable like in PowerShell:
      PowerShell:
      $a = Get-ChildItem $a.Mode I imagine this in AutoIt  $aOutput
      ConsoleWrite($aOutput[i].Mode) Or if I split this command into 2 dimension like:
      For $i To UBound($aOutput)-1 Step 1 ConsoleWrite($aOutput[$i][1]) ConsoleWrite($aOutput[$i][2]) Next  
    • By Mannyfresh31
      Please help with this 3D Array the first example works the secound doesn't.
      Need help to understand how Arrays work.
      Many thanks in advance
      ;First Example Dim $aArray[2][2][2] $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 For $a = 0 to 1 for $b = 0 to 1 for $c = 0 to 1 ConsoleWrite($aArray[$a][$b][$c] & @CRLF) Next Next Next ;Secound Example Local $aArraym [2][2][2]=[[[1,2,],[3,4],[5,6],[7,8]]] For $a = 0 to 1 for $b = 0 to 1 for $c = 0 to 1 ConsoleWrite($aArraym[$a][$b][$c] & @CRLF) Next Next Next  
    • By Hermes
      My _Excel_RangeCopyPaste is not working as intended. What I am trying to accomplish is copy the range B:E using _Excel_RangeCopyPaste in the first row and repeat the same for row 2 and so on.
      ;Skip from reading header columns Local $Skipline = 0 ;0==> first line Local $temprf For $i = 0 To UBound($aArray2) - 1 If $Skipline = $i Then ContinueLoop $temprf &= $aArray2[$i] _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) Local $oTest = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "PasteButton") ;This button will paste values from the Clipboard once clicked _WD_ElementAction($sSession, $oTest, 'click')) Next Here's the full code:
      #Include <Chrome.au3> #Include <wd_core.au3> #Include <wd_helper.au3> #Include <WinHttp.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <Array.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "test.html") Local $oAppl = _Excel_Open() Local $sWorkbook = "test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $oRange = $oWorkbook.ActiveSheet.Range("B:E") ;Skip from reading header columns Local $Skipline = 0 ;0==> first line Local $temprf For $i = 0 To UBound($aArray2) - 1 If $Skipline = $i Then ContinueLoop $temprf &= $aArray2[$i] _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) Local $oTest = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "PasteButton") ;This button will paste values from the Clipboard once clicked _WD_ElementAction($sSession, $oTest, 'click')) Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') Return '{"capabilities":{"alwaysMatch":{"goog:chromeOptions":{"w3c":true,' & _ '"excludeSwitches":["enable-automation"],"useAutomationExtension":false}}}}' EndFunc ;==>SetupChrome For the first row I am trying to copy just B:E with the following info
      Apple Banana Orange Mango and then repeat for row 2, row 3, etc. I've attached the spreadhseet.
      test.xlsxI have also attached the excel file for reference.
×
×
  • Create New...