gpt4 book ai didi

java - "Đ"使用 Java 对越南语文本进行排序时排序不正确

转载 作者:行者123 更新时间:2023-12-02 02:30:28 27 4
gpt4 key购买 nike

排序似乎不适用于此越南文本 Đ

我正在尝试按 wardName 进行排序。包含 Đ 的字符串,排序不正确。

问题出在这个字符串上:wardName":"X。 ĐA PHƯỚC

{"cityId":11,"cityName":"T. AN GIANG","districts":[{"districtId":135,"districtName":"H. AN PHÚ","wards":[{"wardId":"2505","wardName":"TT. AN PHÚ"},{"wardId":"2509","wardName":"TT. LONG BÌNH"},{"wardId":"2507","wardName":"X. KHÁNH AN"},{"wardId":"2508","wardName":"X. KHÁNH BÌNH"},{"wardId":"2510","wardName":"X. NHƠN HỘI"},{"wardId":"2511","wardName":"X. PHÚ HỘI"},{"wardId":"2513","wardName":"X. PHÚ HỮU"},{"wardId":"2512","wardName":"X. PHƯỚC HƯNG"},{"wardId":"2514","wardName":"X. QUỐC THÁI"},{"wardId":"2515","wardName":"X. VĨNH HẬU"},{"wardId":"2516","wardName":"X. VĨNH HỘI ĐÔNG"},{"wardId":"2517","wardName":"X. VĨNH LỘC"},{"wardId":"2518","wardName":"X. VĨNH TRƯỜNG"},{"wardId":"2506","wardName":"X. ĐA PHƯỚC"}]}

{"wardId":"2506","wardName":"X.ĐA PHƯỚC"}:这应该出现在目标字符串之前,但它在末尾显示:{"wardId":"2507","wardName":"X.KHÁNH AN"}

问题似乎是由 Đ 字符引起的。

最佳答案

类似这样的吗?

val sortedList = yourCollection.sortedWith(Comparator { s1, s2 ->
Collator.getInstance(Locale("vi", "VN")).compare(s1.wardName, s2.wardName)
})

关于java - "Đ"使用 Java 对越南语文本进行排序时排序不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57232694/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com