Java中字符串的传统西班牙语排序 [英] Traditional Spanish sorting of Strings in Java

查看:208
本文介绍了Java中字符串的传统西班牙语排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将.NET应用程序转换为Java.该应用程序将读取以下格式的文件:

I'm converting a .NET application into Java. The app reads in a file with this format:

es-MX
jueves
verde
amarillo
blanco
llave
llover
loma
cinco
domingo
rojo

但是我在弄清楚如何根据传统单词排序对西班牙语进行排序时遇到了麻烦.在VB.NET中,您会看到以下内容:

but I'm having a trouble figuring out how to sort Spanish according to the traditional sorting of words. In VB.NET, you'd do see this:

 Dim spainCultureTraditional As CultureInfo = New CultureInfo(&H40A)

但是我在Java中找不到等效的传统排序语言环境.两者之间的唯一区别是es-MX/es-ES llavellover相对于国际排序将被切换.

but I can't find the equivalent traditional sorting locale in Java. The only difference between the two is that in es-MX/es-ES llave and llover would be switched versus the international sorting.

注意:语言环境es-ES在Java中不一定相同,在VB.NET中也不相同.

Note: the locale es-ES is not necessarily the same in Java and it is not the same in VB.NET.

推荐答案

您可能需要自定义的归类规则.这里有一个传统西班牙语的演示:

You might need customised Collation rules. There is a demo for tranditional Spanish here:

https://docs.oracle.com/javase/tutorial/i18n/text/rule.html

摘要代码:

String smallnTilde = "\u00F1";
String capitalNTilde = "\u00D1";

String traditionalSpanishRules = (
    "< a,A < b,B < c,C " +
    "< ch, cH, Ch, CH " +
    "< d,D < e,E < f,F " +
    "< g,G < h,H < i,I < j,J < k,K < l,L " +
    "< ll, lL, Ll, LL " +
    "< m,M < n,N " +
    "< " + smallnTilde + "," + capitalNTilde + " " +
    "< o,O < p,P < q,Q < r,R " +
    "< s,S < t,T < u,U < v,V < w,W < x,X " +
    "< y,Y < z,Z");

RuleBasedCollator spCollator = new RuleBasedCollator(traditionalSpanishRules);

Collections.sort(words, spCollator);
System.out.println(words);

这篇关于Java中字符串的传统西班牙语排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆