tsolrm Posted January 21, 2012 Share Posted January 21, 2012 (edited) Hi, i've got a list in the form of: nick 20 nick2 20 nick3 20 nick25 20 etc It's a very large list. I need to delete a certain entry, say "nick2". I need this to be done as quick as possible. This is what i've come up with. As far a i can see it will do the job but is there an easier way to do this? Thanks $Bans = FileRead ("Statistics.txt") $Bans = StringSplit ($Bans, @LF) $Bans = _ArrayToString ($Bans, "*") $Bans = StringReplace ($Bans, "*nick2 ", "*") $Bans = StringSplit ($Bans, "*", 2) $Bans[0]=UBound ($Bans)-1 For $i = 1 to $Bans [0] $Return = StringIsDigit (StringStripCR($Bans[$i])) If $Return = 1 Then $Bans [$i] = "" Next $Bans = _ArrayToString ($Bans, "*") $Bans = StringReplace ($Bans, "**", "*") $Bans = StringSplit ($Bans, "*", 2) $Bans[0]=UBound ($Bans)-1 _ArrayDisplay ($Bans) Edited January 21, 2012 by tsolrm Link to comment Share on other sites More sharing options...
water Posted January 21, 2012 Share Posted January 21, 2012 Is it always "name-to-be-deleted 20" or can the rest of the record change? How big is your file (MB, GB)? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 21, 2012 Moderators Share Posted January 21, 2012 tsolrm, I would do it like this: #include <Array.au3> #include <File.au3> ; Declare initial variables Global $aBans $sFile = "Statistics.txt" $sDelete = "nick2" ; Read file _FileReadToArray($sFile, $aBans) ; Just to show what you read _ArrayDisplay($aBans) ; Find the offending name - note you need to use the partial search parameter $iIndex = _ArraySearch($aBans, $sDelete, 1, 0, 0, 1) ; And if found - delete If Not @error Then _ArrayDelete($aBans, $iIndex) EndIf ; Just to show you it has been deleted _ArrayDisplay($aBans) ; And rewrite the file - note how to avoid the count in the [0] element _FileWriteFromArray($sFile, $aBans, 1) All clear? M23 tsolrm 1 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...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 Is it always "name-to-be-deleted 20" or can the rest of the record change?How big is your file (MB, GB)?its always in the form "nick number" Link to comment Share on other sites More sharing options...
water Posted January 21, 2012 Share Posted January 21, 2012 As speed matters I would avoid the _Array* functions. If the size of the file is < 2GB (I think this is the limit for a string, but I will check) you can read the whole file to a variable and do a stringreplace and then rewrite the file. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted January 21, 2012 Share Posted January 21, 2012 its always in the form "nick number"Does this mean the number changes or is it always "20"? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 tsolrm, I would do it like this: #include <Array.au3> #include <File.au3> ; Declare initial variables Global $aBans $sFile = "Statistics.txt" $sDelete = "nick2" ; Read file _FileReadToArray($sFile, $aBans) ; Just to show what you read _ArrayDisplay($aBans) ; Find the offending name - note you need to use the partial search parameter $iIndex = _ArraySearch($aBans, $sDelete, 1, 0, 0, 1) ; And if found - delete If Not @error Then _ArrayDelete($aBans, $iIndex) EndIf ; Just to show you it has been deleted _ArrayDisplay($aBans) ; And rewrite the file - note how to avoid the count in the [0] element _FileWriteFromArray($sFile, $aBans, 1) All clear? M23 clear indeed. Is _ArraySearch quicker then doing what i did? Link to comment Share on other sites More sharing options...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 Does this mean the number changes or is it always "20"?Yes it changes Link to comment Share on other sites More sharing options...
water Posted January 21, 2012 Share Posted January 21, 2012 I would suggest to test Melba's code with your data. If you are satisfied with the speed stay with this solution. If not I'm sure speed can be enhanced. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 Thank you guys Link to comment Share on other sites More sharing options...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 There is a possibility that there would be two "nick2" or more. And I want to delete all of them. My code accounts for this but ArraySearch stops the search as soon as it finds the first nick2 doesn't it? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 21, 2012 Moderators Share Posted January 21, 2012 tsolrm,Put the _ArraySearch/Delete section in a loop until the search returns an error. M23 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...
water Posted January 21, 2012 Share Posted January 21, 2012 Right. You would have to do _ArraySearch until you get -1 as return value. Make sure to set parameter $iStart to the current record (= the return value of the previous _ArraySearch call) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 Partial search wouldn't work properly here because if you are searching for "nick" for example then all of the elements in this case have "nick". In reality one nickname could be contained within another. Link to comment Share on other sites More sharing options...
water Posted January 21, 2012 Share Posted January 21, 2012 If you are familiar with regular expressions you can read the file into a string, replace all occurences of "nick2 number@CRLF" using StringRegExpReplace and then write the file to disk. tsolrm 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 21, 2012 Moderators Share Posted January 21, 2012 tsolrm,Then please give us a valid set of data to work with. We cannot be expected to offer sensible help if you keep altering your requriements. M23 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...
tsolrm Posted January 21, 2012 Author Share Posted January 21, 2012 tsolrm,Then please give us a valid set of data to work with. We cannot be expected to offer sensible help if you keep altering your requriements. M23Well I suppose if I do a partial search for "nick " (with a space) than this will only find the entries that contain "nick 20". Link to comment Share on other sites More sharing options...
Spiff59 Posted January 21, 2012 Share Posted January 21, 2012 If you'll be doing multiple deletes, then using the _Array functions wouldn't be the way to go.As you'll pass through your data multiple times and execute multiple Redims.Maybe do it manually like here: 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