AuToItItAlIaNlOv3R Posted April 4, 2011 Share Posted April 4, 2011 Hi to all, i've a really big .ini file ~10K line. But there are a lot of equal key...there is a function or metodo to delete the equal key...for example : [Key] try=lol try=lol mean=try In this example i would like to delete one "try" key...becouse there are 2 equals... How i can do that? Hi! Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 4, 2011 Share Posted April 4, 2011 I think this function, StringReplace, could be used here. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 4, 2011 Moderators Share Posted April 4, 2011 AuToItItAlIaNlOv3R,_ArrayUnique should do the trick. Read the file into an array with _FileReadToArray and run _ArrayUnique on the result:#include <Array.au3> Global $aArray[4] = ["[Key]", "try=lol", "try=lol", "mean=try"] $aUnique = _ArrayUnique($aArray) _ArrayDisplay($aUnique)If you are likely to have the same key in several sections, then you may have to use the function on each section at a time. 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...
UEZ Posted April 4, 2011 Share Posted April 4, 2011 (edited) Here another method: expandcollapse popup#include <Array.au3> $a1 = IniReadSection("Test.ini", "key") _ArrayDisplay($a1, "Before") $a2 = ArrayUnique($a1, 1, 1) _ArrayDisplay($a2, "After") ; #FUNCTION# ============================================================================ ; Name.............: ArrayUnique ; Description ...: Returns the Unique Elements of a 1-dimensional or 2-dimensional array. ; Syntax...........: _ArrayUnique($aArray[, $iBase = 0, oBase = 0]) ; Parameters ...: $aArray - The Array to use ; $iBase - [optional] Is the input Array 0-base or 1-base index. 0-base by default ; $oBase - [optional] Is the output Array 0-base or 1-base index. 0-base by default ; Return values: Success - Returns a 1-dimensional or 2-dimensional array containing only the unique elements ; Failure - Returns 0 and Sets @Error: ; 0 - No error. ; 1 - Returns 0 if parameter is not an array. ; 2 - Array has more than 2 dimensions ; 3 - Array is already unique ; 4 - when source array is selected as one base but UBound(array) - 1 <> array[0] / array[0][0] ; 5 - Scripting.Dictionary cannot be created for 1D array unique code ; Author .........: UEZ 2010 for 2D-array, Yashied for 1D-array (modified by UEZ) ; Version ........: 0.96 Build 2010-11-20 Beta ; Remark ........: check is always case sensitive ; ======================================================================================= Func ArrayUnique($aArray, $iBase = 0, $oBase = 0) If Not IsArray($aArray) Then Return SetError(1, 0, 0) ;not an array If UBound($aArray, 0) > 2 Then Return SetError(2, 0, 0) ;array is greater than a 2D array If UBound($aArray) = $iBase + 1 Then Return SetError(3, 0, $aArray) ;array is already unique because of only 1 element Local $dim = UBound($aArray, 2), $i If $dim Then ;2D array If $iBase And UBound($aArray) - 1 <> $aArray[0][0] Then Return SetError(4, 0, 0) Local $oD = ObjCreate('Scripting.Dictionary') If @error Then Return SetError(5, 0, 0) Local $i, $j, $k = $oBase, $l, $s, $aTmp, $flag, $sSep = Chr(01) Local $aUnique[UBound($aArray)][$dim] If Not $oBase Then $flag = 2 For $i = $iBase To UBound($aArray) - 1 For $j = 0 To $dim - 1 $s &= $aArray[$i][$j] & $sSep Next If Not $oD.Exists($s) And StringLen($s) > 3 Then $oD.Add($s, $i) $aTmp = StringSplit(StringTrimRight($s, 1), $sSep, 2) For $l = 0 To $dim - 1 $aUnique[$k][$l] = $aTmp[$l] Next $k += 1 EndIf $s = "" Next $oD.RemoveAll $oD = "" If $k > 0 Then If $oBase Then $aUnique[0][0] = $k - 1 ReDim $aUnique[$k][$dim] Else ReDim $aUnique[1][$dim] EndIf Else ;1D array If $iBase And UBound($aArray) - 1 <> $aArray[0] Then Return SetError(4, 0, 0) Local $sData = '', $sSep = ChrW(160), $flag For $i = $iBase To UBound($aArray) - 1 If Not IsDeclared($aArray[$i] & '$') Then Assign($aArray[$i] & '$', 0, 1) $sData &= $aArray[$i] & $sSep EndIf Next If Not $oBase Then $flag = 2 Local $aUnique = StringSplit(StringTrimRight($sData, 1), $sSep, $flag) EndIf Return $aUnique EndFunc ;==>ArrayUnique Br, UEZ Edited April 4, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
StungStang Posted April 4, 2011 Share Posted April 4, 2011 (edited) Try with _ArrayUnique. Edited April 6, 2011 by StungStang Link to comment Share on other sites More sharing options...
iamtheky Posted April 5, 2011 Share Posted April 5, 2011 something like so? named your ini file test.ini for the example #include <array.au3> Local $Array1 , $Array2 $Array1 = IniReadSection ("test.ini" , "KEY") _ArrayDelete ($Array1 , 0) $Array2 = $Array1 for $k = ubound($Array1) - 1 to 0 step -1 $find = _ArrayFindAll ($Array2, $Array1[$k][0] , 0 , 0 , 0 , 0 , 0) for $m = ubound ($find) - 1 to 1 step -1 _ArrayDelete($Array2, $find[$m]) next next _ArrayDisplay ($Array2) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
martin Posted April 5, 2011 Share Posted April 5, 2011 Wouldn't this do what is required? FileDelete("copyTest1.ini");in case it already exists $aSectionnames = IniReadSectionNames("test1.ini");read the sections For $n = 1 To $aSectionnames[0] $aNames = IniReadSection("test1.ini", $aSectionnames[$n]);read the names in the sections For $j = 1 To $aNames[0][0] IniWrite("copyTest1.ini", $aSectionnames[$n], $aNames[$j][0], IniRead("test1.ini", $aSectionnames[$n], $aNames[$j][0], ''));add to the copy of the ini Next Next Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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