How to sort words in file.txt?

English main discussion
Post Reply
  • Author
  • Message
Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

How to sort words in file.txt?

Post 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

Offline
Posts: 874
Joined: Sat Jan 16, 2010 2:03 pm

Re: How to sort words in file.txt?

Post 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

Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post 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

Offline
Posts: 874
Joined: Sat Jan 16, 2010 2:03 pm

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

Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post 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

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post 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;
  }
}

Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post 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.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post 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;
  }
}


Offline
Posts: 282
Joined: Thu Sep 10, 2015 9:53 am
Location: Deutschland

Post by sexy96 »

Thank you very much, it works great :D
Post Reply