locked
Sort oddity when array is initialized via Get-Content vs inline RRS feed

  • General discussion

  • Create data.txt via Notepad containing three lines:

    ABCZ
    ABC_
    ABCA

    Saved as ANSI.

    Get-Content -Encoding Byte data.txt
    65 66 67 90 13 10  65 66 67 95 13 10  65 66 67 65 13 10
    $a = Get-Content data.txt
    $b = @( 'ABCZ', 'ABC_', 'ABCA' )
    $a[0] -eq $b[0]; $a[1] -eq $b[1]; $a[2] -eq $b[2];
    True
    True
    True
    [System.Collections.ArrayList] $al = $a
    [System.Collections.ArrayList] $bl = $b
    $al[0] -eq $bl[0]; $al[1] -eq $bl[1]; $al[2] -eq $bl[2];
    True
    True
    True
    $al.Sort( [System.StringComparer]::Ordinal )
    $bl.Sort( [System.StringComparer]::Ordinal )
    $al
    ABC_
    ABCA
    ABCZ
    $bl
    ABCA
    ABCZ
    ABC_
    Why do the two ArrayLists sort differently?

    • Edited by BAH Humbug Monday, September 15, 2014 6:38 PM Spelling
    • Changed type Bill_Stewart Monday, November 3, 2014 3:55 PM Discussion
    Monday, September 15, 2014 5:59 PM

All replies