polps Posted March 14, 2019 Posted March 14, 2019 Hi all. I have two text file to compare. I'm comparing them using a commercial comparison tool (Beyond Compare) I'm receiving the first file as input. This file is already sorted using Notepad++ function The second file is the output of my AU3 script. I'm sorting the records using _ArraySort function. Then I write the sorted array in a text file. Unfortunately, I see some differences, because the two file have same records but different order. (see below the example of diff) I don't want to modify the file I receive as input, but - of course - I can process in different way the second file I produce. How can I use the same sorting algorithm used by Notepad++ ?? Thanks for any suggestion First file (notepad++ sorting) APR_SCC_CBI APR_SCC_CBII APR_SCC_CBIII APR_SCC_CBIII_DM APR_SCC_CBIII_DMIS APR_SCC_CBIII_IS APR_SCC_CBIII_NO APR_SCC_CBIII_O APR_SCC_CBII_DM APR_SCC_CBII_DMIS APR_SCC_CBII_IS APR_SCC_CBII_NO APR_SCC_CBII_O APR_SCC_CBI_DM APR_SCC_CBI_DMIS APR_SCC_CBI_IS APR_SCC_CBI_NO APR_SCC_CBI_O Second file (_ArraySort function) APR_SCC_CBI APR_SCC_CBI_DM APR_SCC_CBI_DMIS APR_SCC_CBI_IS APR_SCC_CBI_NO APR_SCC_CBI_O APR_SCC_CBII APR_SCC_CBII_DM APR_SCC_CBII_DMIS APR_SCC_CBII_IS APR_SCC_CBII_NO APR_SCC_CBII_O APR_SCC_CBIII APR_SCC_CBIII_DM APR_SCC_CBIII_DMIS APR_SCC_CBIII_IS APR_SCC_CBIII_NO APR_SCC_CBIII_O
FrancescoDiMuro Posted March 14, 2019 Posted March 14, 2019 3 hours ago, polps said: The second file is the output of my AU3 script. Which we can only imagine. Post it Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Jfish Posted March 14, 2019 Posted March 14, 2019 (edited) You can do it using SQLite (I was too lazy to change the table name from the help file example, so you can obviously change it): expandcollapse popup#include <Array.au3> #include <MsgBoxConstants.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Local $aResult, $iRows, $iColumns, $iRval; for sqllite stuff global $sortArray[18]=['APR_SCC_CBI', _ 'APR_SCC_CBI_DM', _ 'APR_SCC_CBI_DMIS', _ 'APR_SCC_CBI_IS', _ 'APR_SCC_CBI_NO', _ 'APR_SCC_CBI_O', _ 'APR_SCC_CBII', _ 'APR_SCC_CBII_DM', _ 'APR_SCC_CBII_DMIS', _ 'APR_SCC_CBII_IS', _ 'APR_SCC_CBII_NO', _ 'APR_SCC_CBII_O', _ 'APR_SCC_CBIII', _ 'APR_SCC_CBIII_DM', _ 'APR_SCC_CBIII_DMIS', _ 'APR_SCC_CBIII_IS', _ 'APR_SCC_CBIII_NO', _ 'APR_SCC_CBIII_O' ] ;_ArrayDisplay($sortArray) _SQLite_Startup() If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!") Exit -1 EndIf ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) _SQLite_Open() ; Open a :memory: database If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!") Exit -1 EndIf If Not _SQLite_Exec(-1, "CREATE TEMP TABLE persons (Name);") = $SQLITE_OK Then _ MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) for $a=0 to ubound($sortArray)-1 If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ("&"'"&$sortArray[$a]&"'"&");") = $SQLITE_OK Then _ ; MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) next ; Query $iRval = _SQLite_GetTable(-1, "SELECT * FROM persons ORDER BY Name;", $aResult, $iRows, $iColumns) If $iRval = $SQLITE_OK Then _ArrayDisplay($aResult, "Query Result") Else MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg()) EndIf _SQLite_Close() _SQLite_Shutdown() Edited March 14, 2019 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Malkey Posted March 15, 2019 Posted March 15, 2019 Last Tuesday I posted an _ArraySort() with case sensitivity in the Examples forum. The function _ArraySortc() gives the same results as notepad++ sorting - with case sensitivity. #include <ArrayMultiSortCase.au3> ; Found @ https://www.autoitscript.com/forum/topic/198148-_arraymultisort-sort-multiple-columns-with-case-sensitivity/? local $a[]= [ _ "APR_SCC_CBI","APR_SCC_CBI_DM","APR_SCC_CBI_DMIS","APR_SCC_CBI_IS","APR_SCC_CBI_NO","APR_SCC_CBI_O","APR_SCC_CBII", _ "APR_SCC_CBII_DM","APR_SCC_CBII_DMIS","APR_SCC_CBII_IS","APR_SCC_CBII_NO","APR_SCC_CBII_O","APR_SCC_CBIII","APR_SCC_CBIII_DM", _ "APR_SCC_CBIII_DMIS","APR_SCC_CBIII_IS","APR_SCC_CBIII_NO","APR_SCC_CBIII_O"] _ArraySortc($a, 0, 0, 0, 0, 0, 1) ; $iDescending = 0(ascending); $iCase = 1(Case sensitive) _ArrayDisplay($a, "First file: notepad++ sorting" ) _ArraySort($a) _ArrayDisplay($a, "Second file: _ArraySort function" ) Jfish 1
polps Posted March 15, 2019 Author Posted March 15, 2019 Hi guys and thanks. I will try both solutions and I will choose. Thanks again
Jfish Posted March 15, 2019 Posted March 15, 2019 @Malkey That is very cool! I was searching around for the 1D array ability to do that and didn't see anything - most array sort UDFs seem focused on 2D arrays. It would be great if some of those sort options for both get folded into the standard array.au3 UDF _arraySort() function. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
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