Search code examples
arraysactionscript-3sortingnon-english

ActionScript - Array.sortOn() For Non-English Data?


this is an array of objects that i want to alphabetize:

var streets:Array = new Array();
streets.push({name:"Édouard-Montpetit"});
streets.push({name:"Alexandre de Sève"});
streets.push({name:"Van Horne"});
streets.push({name:"Atwater"});

now i'll sort my array:

streets.sortOn("name", Array.CASEINSENSITIVE);

//Sorted
Alexandre de Sève
Atwater
Van Horne
Édouard-Montpetit

the accent above the E in Édouard-Montpetit, and any other first letter with a non-english accent is sorted after Z.

any ideas how i can sort this correctly? i do not have access to the named data.


Solution

  • I know this is late, but for anyone going through this answer, you could pass a Collator object to the Array.sort() method. A simple example from the documentation:

     var words:Array = new  Array("coté", "côte"); 
     var sorter:Collator = new Collator("fr-FR", CollatorMode.SORTING); 
     words.sort(sorter.compare); 
     trace(words);// côte,coté 
    

    Hope this helps