slvtn666 Posted July 3, 2018 Share Posted July 3, 2018 Hello! Im new to autoit. I have .csv file with 8 coloumns and over 7-9k rows with tab delimeter. I split this file into 2D array using _FileReadToArray($file, $retArray, '', @TAB). In second column of .csv file i have digit based string, this strings is not unique: for example: 57814510303 57814510303 57814510303 57954184645 57986498899 57986498899 I want to get unique values in separate array, now im getting result using following code: Local $retArray _FileReadToArray($file, $retArray, '', @TAB) Local $idArray[UBound($retArray) - 1] For $i = 1 To UBound($retArray) - 1 _ArrayPush($idArray, $retArray[$i][1]) Next $uniqueIdArray = _ArrayUnique($idArray, "", "", "", 0, "") The script part with For $i = 1 To UBound($retArray) - 1 _ArrayPush($korobIdArray, $retArray[$i][1]) Next takes over 52 seconds for 7500 entries. May be i should use another function instead _ArrayAdd to make it faster? Sorry for my bad english, and thank you for your replies Link to comment Share on other sites More sharing options...
LarsJ Posted July 3, 2018 Share Posted July 3, 2018 Replace your _ArrayPush loop with this: For $i = 1 To UBound($retArray) - 1 $korobIdArray[$i] = $retArray[$i][1] Next slvtn666 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
slvtn666 Posted July 3, 2018 Author Share Posted July 3, 2018 3 minutes ago, LarsJ said: Replace your _ArrayPush loop with this: For $i = 1 To UBound($retArray) - 1 $korobIdArray[$i] = $retArray[$i][1] Next Wow, thanks, now it takes miliseconds... its very obvious, why did not I think of it myself. Thank you, i really appreciate your help Link to comment Share on other sites More sharing options...
Vincor Posted July 3, 2018 Share Posted July 3, 2018 And now, just for the fun of it, a solution using Regular Expressions: #include <StringConstants.au3> #include <Array.au3> Local $korobIdArray = StringRegExp(FileRead("file.tsv"),"(?m)^[^\t]\t(.*)$",$STR_REGEXPARRAYGLOBALMATCH) Local $uniqueIdArray = _ArrayUnique($korobIdArray, 0, 0, 0, 0) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 3, 2018 Moderators Share Posted July 3, 2018 Moved to the appropriate forum. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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