-1

I'm looking for a way to truly alphabetize a list. Assuming it's a list of basic words, such as:
Black
Green
The Red
Blue
Waxy
Living
Porous
Solid
Liquid
Violet

Is there a way to modify this code to alphabetize the list where "The Red" comes before "Solid"? Here's what I have so far:

SaveVar=%ClipboardAll%
Clipboard=
Send ^c
ClipWait, 0.5
Sort clipboard, CL
;Process exceptions
Sort := RegExOmit (Sort, "The")
Send ^v
Sleep 100
Clipboard=%SaveVar%
SaveVar=
return
2501
  • 25,460
  • 4
  • 47
  • 87

1 Answers1

0

Write a custom comparison function that ignores the starting "The " substring.

list = Black`nGreen`nThe Red`nBlue`nWaxy`nLiving`nPorous`nSolid`nLiquid`nViolet`nThe Azure

Sort , list , F Compare
MsgBox, %list%

Compare( a , b )
{
    arem := RegExReplace(a, "A)The " , "" )
    brem := RegExReplace(b, "A)The " , "" )

    return arem > brem ? 1 : arem < brem ? -1 : 0
}

Regular expressions are used to remove the substring "The " from the string and the result stored in a temporary string, which is then used for comparison.

The substring must start at the beginning of the string, regex option A), and must include a space immediately after The.

2501
  • 25,460
  • 4
  • 47
  • 87
  • Thanks, this helped quite a bit. I played with it some more and found how to add more exceptions to the alphabetizer. Compare( a , b ) { arem := RegExReplace(a, ")The |the |A |a |An |an " , "" ) brem := RegExReplace(b, ")The |the |A |a |An |an " , "" ) return arem > brem ? 1 : arem < brem ? -1 : 0 } – Shaun Doeden Apr 14 '16 at 16:10