Sorting a String array and ignoring case

前端 未结 5 1807
眼角桃花
眼角桃花 2020-12-29 05:09

The code below works for sorting an array of strings if they are all lowercase or all uppercase but I want to ignore case when I sort. How could I do this? The following is

5条回答
  •  暖寄归人
    2020-12-29 05:32

    You can convert the String to lowercase and then compare it:

    array.sort{ $0.lowercaseString < $1.lowercaseString }
    

提交回复
热议问题