• Sort string list in alphabetical order but ignore case

    From Shaun Kulesa@21:1/5 to All on Sun Oct 1 07:42:12 2023
    I am trying to order a list alphabetically but is ordering it so the strings starting with uppercase are ordered first then the strings with lowercase are ordered last.

    How can I ignore the case of the strings?

    Example output:

    Ttk_PackBox
    Ttk_PadBox
    Ttk_PlaceBox
    Ttk_RelievePadding
    Ttk_StickBox
    Ttk_UniformPadding
    after
    append
    apply
    argc
    argv
    argv0
    array
    attemptckalloc
    attemptckrealloc
    auto_execok
    auto_import
    auto_load
    auto_mkindex
    auto_path
    auto_qualify
    auto_reset
    bell
    bgerror

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Shaun Kulesa@21:1/5 to All on Sun Oct 1 07:43:32 2023
    Just to note, I am using lsort.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Shaun Kulesa@21:1/5 to All on Sun Oct 1 09:01:14 2023
    Thanks so much for the arg examples, it has helped me understand each arg.

    I completely missed the nocase arg on the docs.

    Thanks!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to Shaun Kulesa on Sun Oct 1 09:08:04 2023
    Shaun Kulesa schrieb am Sonntag, 1. Oktober 2023 um 18:01:18 UTC+2:
    Thanks so much for the arg examples, it has helped me understand each arg.

    I completely missed the nocase arg on the docs.

    Thanks!

    # https://www.tcl-lang.org/man/tcl/TclCmd/lsort.htm
    #
    # -nocase
    # Causes comparisons to be handled in a case-insensitive manner.
    # Has no effect if combined with the -dictionary, -integer, or -real options.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From greg@21:1/5 to Shaun Kulesa on Sun Oct 1 08:56:07 2023
    Shaun Kulesa schrieb am Sonntag, 1. Oktober 2023 um 16:43:36 UTC+2:
    Just to note, I am using lsort.


    # https://www.tcl-lang.org/man/tcl/TclCmd/lsort.htm
    # -ascii
    # Use string comparison with Unicode code-point collation order
    # (the name is for backward-compatibility reasons.) This is the default.

    package require struct::list

    set l [split {Ttk_PackBox
    Ttk_PadBox
    Ttk_PlaceBox
    Ttk_RelievePadding
    Ttk_StickBox
    Ttk_UniformPadding
    after
    append
    apply
    argc
    argv
    argv0
    array
    attemptckalloc
    attemptckrealloc
    auto_execok
    auto_import
    auto_load
    auto_mkindex
    auto_path
    auto_qualify
    auto_reset
    bell
    bgerror} '\n']


    set s [ ::struct::list shuffle $l]
    puts "l:\n $l"
    puts "s:\n $s"
    puts "nocase:\n [lsort -nocase $s]"
    puts "ascii:\n [lsort -ascii $s]"
    puts "default:\n [lsort $s]"
    puts "dictionary:\n [lsort -dictionary $s]"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to Shaun Kulesa on Sun Oct 1 16:17:36 2023
    From 'man 3tcl lsort':

    -dictionary
    Use dictionary-style comparison. This is the same as -ascii ex-
    cept (a) case is ignored except as a tie-breaker and (b) if two
    strings contain embedded numbers, the numbers compare as inte-
    gers, not characters. For example, in -dictionary mode, bigBoy
    sorts between bigbang and bigboy, and x10y sorts between x9y and
    x11y. Overrides the -nocase option.



    At Sun, 1 Oct 2023 07:42:12 -0700 (PDT) Shaun Kulesa <shaunkulesa@gmail.com> wrote:


    I am trying to order a list alphabetically but is ordering it so the strings starting with uppercase are ordered first then the strings with lowercase are ordered last.

    How can I ignore the case of the strings?

    Example output:

    Ttk_PackBox
    Ttk_PadBox
    Ttk_PlaceBox
    Ttk_RelievePadding
    Ttk_StickBox
    Ttk_UniformPadding
    after
    append
    apply
    argc
    argv
    argv0
    array
    attemptckalloc
    attemptckrealloc
    auto_execok
    auto_import
    auto_load
    auto_mkindex
    auto_path
    auto_qualify
    auto_reset
    bell
    bgerror



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)