Page 1 of 1

How to sort words in file.txt?

Posted: Tue Oct 24, 2017 8:19 am
by sexy96
I have sorted the words

a
A
b
B
c
C

How to sort them in this way?
a
b
c
A
B
C
or
A
B
C
a
b
c

Notepad ++ is an option
Image

Re: How to sort words in file.txt?

Posted: Tue Oct 24, 2017 12:38 pm
by opk44
sexy96 wrote:...
or
A
B
C
a
b
c
See docs (Format-Eng.txt)

Code: Select all

*****************************************************************
***                Format AkelPad plugin v3.3                 ***
*****************************************************************
...
Call("Format::LineSortStrAsc", FLAGS)
  Parameters:
    FLAGS (sum of the following members):
      1  Match case.
      2  Match locale (slower).
      By default: 0.
...
So, you can use in Context Menu:
"Sorts lines by string ascending + Match case" Call("Format::LineSortStrAsc", 1) Icon("%a\AkelFiles\Plugs\Format.dll", 1)
Or you can use "SortLines.js"
Options:
[*]Key 2-Line content [_] Ignore Case
[*]Entire Line (*) String

Posted: Wed Oct 25, 2017 6:02 am
by sexy96
The problem is that in the dictionary I have words starting with ć, Ć, ś, Ś - e.t.c
a
A
C
ć
d
Ś
w
Z

How to get this effect?

a <- lower case
ć
d
w
A <- big case
C
Ś
Z

Posted: Wed Oct 25, 2017 2:49 pm
by opk44
sexy96
I don't have Polish locale, so I can't reproduce it. But IF YOU HAVE, than try to use FLAG = 3 (Match case + Match locale) instead "1"

Posted: Wed Oct 25, 2017 3:00 pm
by sexy96
it does not work

"Sorts lines by string ascending + Match case" Call("Format::LineSortStrAsc", 3) Icon("%a\AkelFiles\Plugs\Format.dll", 1)

a
A
C
ć
Ć
Ś
w
Z

Posted: Wed Oct 25, 2017 7:23 pm
by KDJ
sexy96

Try this script:

Code: Select all

var bAscending = true;
var oSys  = AkelPad.SystemFunction();
var aLine = AkelPad.GetTextRange(0, -1).split("\r").sort(StrCompare);

AkelPad.SetSel(0, -1);
AkelPad.ReplaceSel(aLine.join("\r\n"));

function StrCompare(s1, s2)
{
  var bUpper1 = (s1.charAt(0) == s1.charAt(0).toUpperCase());
  var bUpper2 = (s2.charAt(0) == s2.charAt(0).toUpperCase());

  if (bAscending)
  {
    if (bUpper1 == bUpper2)
      return oSys.Call("Kernel32::lstrcmpiW", s1, s2);
    else if (bUpper1 && (! bUpper2))
      return 1;
    else
      return -1;
  }
  else
  {
    if (bUpper1 == bUpper2)
      return oSys.Call("Kernel32::lstrcmpiW", s2, s1);
    else if (bUpper1 && (! bUpper2))
      return -1;
    else
      return 1;
  }
}

Posted: Thu Oct 26, 2017 5:36 am
by sexy96
Dzięki, działa super.

Można to trochę zmodyfikować?

Problem w tym, że to zawsze sortuje cały tekst a nie zaznaczony.
Jak zaznaczę część to przed sortowaniem,
następuje zmiana zaznaczenia na cały tekst.

Posted: Thu Oct 26, 2017 4:57 pm
by KDJ
sexy96

Maybe in this way:

Code: Select all

var bAscending = true;
var oSys = AkelPad.SystemFunction();

if (AkelPad.GetSelStart() == AkelPad.GetSelEnd())
  AkelPad.SetSel(0, -1);

AkelPad.ReplaceSel(AkelPad.GetSelText().split("\r").sort(StrCompare).join("\r\n"));

function StrCompare(s1, s2)
{
  var bUpper1 = (s1.charAt(0) == s1.charAt(0).toUpperCase());
  var bUpper2 = (s2.charAt(0) == s2.charAt(0).toUpperCase());

  if (bAscending)
  {
    if (bUpper1 == bUpper2)
      return oSys.Call("Kernel32::lstrcmpiW", s1, s2);
    else if (bUpper1 && (! bUpper2))
      return 1;
    else
      return -1;
  }
  else
  {
    if (bUpper1 == bUpper2)
      return oSys.Call("Kernel32::lstrcmpiW", s2, s1);
    else if (bUpper1 && (! bUpper2))
      return -1;
    else
      return 1;
  }
}


Posted: Thu Oct 26, 2017 6:19 pm
by sexy96
Thank you very much, it works great :D