Jump to content

Recommended Posts

Posted

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
 

 

 

 

Posted (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): 

#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()

image.png.4a7da45cc9ee23e8edfd214481a62a20.png

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Posted

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" )

 

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.
×
×
  • Create New...