Sign in to follow this  
Followers 0
water

Sort with characters lower than space

7 posts in this topic

#1 ·  Posted (edited)

I hope the title of this thread isn't too misleading - but I could think of a better one :D

I need to sort an 1D-array. Some of the records contain a separator character (now "\") which should come first in the sorting order. I tried every ASCII code from 1 to 31 but all of this records come at the end of the sorted array. The space character is ASCII code 32 so I thought if I used a code < 32 as separator this records would come first.

Example:

"axb" should come before "a b" where x can b any character.

Is there a solution to this problem? Thanks in advance!

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites



_ArraySort collation order depends on your current locale.

Run this to find a suitable separator (rigth column is decimal value of codepoint).

#include <Array.au3>
Local $chr[0x100][2]
For $i = 0 To 0xff
$chr[$i][0] = ChrW($i)
$chr[$i][1] = $i
Next
_ArraySort($chr)
_ArrayDisplay($chr)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I think I found the problem. _ArraySort uses StringCompare. With the flag set to default (0 = not case sensitive, using the user's locale) my sort order doesn't work. But when I set the flag to 2 (not case sensitive, using a basic/faster comparison) everything works fine.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sure, flag 2 reverst to a binary compare, so ASCII order is preserved.

Using the vanilla _ArraySort (hence flag=0) my locale sets the Unicode Soft Hyphen 0xAD ahead (considering only chars < 0x100).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I have been playing with your original script and tested the soft hyphen you mentioned in your last post.

I got strange results. When I just StringCompare a single character then the hypen is "less" then space. If I concatenate it to a longer string then suddenly the string with the hypen is "greater".

Does the concatenation operator somehow change the string?

The following code writes the table index, the ascii code plus the two comparison results to the console:

#include <Array.au3>
Local $chr[0x100][2]
For $i = 0 To 0xff
    $chr[$i][0] = ChrW($i)
    $chr[$i][1] = $i
Next
_ArraySort($chr)
_ArrayDisplay($chr)
For $i = 0 To 0x20
    ConsoleWrite($i & " " & $chr[$i][1] & " " & StringCompare($chr[$i][0], " ") & " " & StringCompare("a" & $chr[$i][0] & "b", "a" & " " & "b") & @CRLF)
Next

I don't understand why column 3 and 4 are different. Does anyone?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Most probably because of the options used for the Windows CompareString function I guess it calls.

You're likely get unexpected results with varying options, some are very useful but since we have little clue as to what these options are, we can only guess.

Try expanding the Unicode range of the array to, say 0x1000. This will bring in Unicode characters perhaps more "stable" than this "soft hyphen".

Geez, just tried: looks even weirder than I thought.

I need to move. I'll be back to this later.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I think someone else already had the

I didn't have the time yet to read the whole thread. Hopefully it contains a solution.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0