[英]Sorting Accented Characters
I'm trying to sort a list of strings with accented characters eg ["Zebra", "Apple", "Ähhhh"]
and I want it to look like ["Apple", "Ähhhh", "Zebra"]
我正在尝试对带有重音符号的字符串列表进行排序,例如["Zebra", "Apple", "Ähhhh"]
并且希望它看起来像["Apple", "Ähhhh", "Zebra"]
Just running list.sort()
gives me ["Apple","Zebra","Ähhhh"]
刚运行list.sort()
会给我["Apple","Zebra","Ähhhh"]
Is there another built in function (like localeCompare
) that will let me sort this in the way I want it to be? 是否有另一个内置函数(如localeCompare
)可以让我按照自己的意愿对它进行排序?
Thanks! 谢谢!
In general, yes, you can sort by different locale. 通常,是的,您可以按不同的语言环境进行排序。
let ar = ["Apple","Zebra","Ähhhh"];
ar.sort((a,b) => a.localeCompare(b, 'en'))
However, as to the exact sorting you're looking for, you'll have to replace 'en' with the appropriate locale, if there is one. 但是,关于要查找的确切排序,如果有,则必须用适当的语言环境替换“ en”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.