Java. Ignore accents when comparing strings(爪哇.比较字符串时忽略重音符号)
问题描述
问题很简单.JAVA中是否有任何函数可以比较两个字符串并忽略重音字符返回true?
The problem it's easy. Is there any function in JAVA to compare two Strings and return true ignoring the accented chars?
即
String x = "Joao";
String y = "João";
返回相等的.
谢谢
推荐答案
我认为你应该使用 Collator 类.它允许您设置强度和语言环境,它会适当地比较字符.
I think you should be using the Collator class. It allows you to set a strength and locale and it will compare characters appropriately.
来自 Java 1.6 API:
From the Java 1.6 API:
您可以设置整理者的强度属性来确定水平差异被认为是显着的比较.四大实力是提供:小学、中学、第三和相同的.最正确语言优势分配功能取决于语言环境.为了例如,在捷克语中,e"和f"是考虑主要差异,而e"和ě"是次要区别,e"和E"是三级差异和 "e" 和 "e" 是相同的.
You can set a Collator's strength property to determine the level of difference considered significant in comparisons. Four strengths are provided: PRIMARY, SECONDARY, TERTIARY, and IDENTICAL. The exact assignment of strengths to language features is locale dependant. For example, in Czech, "e" and "f" are considered primary differences, while "e" and "ě" are secondary differences, "e" and "E" are tertiary differences and "e" and "e" are identical.
我认为这里的重点(人们试图提出的)是Joao"和João"永远不应该被认为是平等的,但是如果你正在做排序你不希望他们根据他们的 ASCII 值,因为那样你会得到像 Joao、John、João 这样的东西,这不好.使用 collator 类肯定可以正确处理这个问题.
I think the important point here (which people are trying to make) is that "Joao"and "João" should never be considered as equal, but if you are doing sorting you don't want them to be compared based on their ASCII value because then you would have something like Joao, John, João, which is not good. Using the collator class definitely handles this correctly.
这篇关于爪哇.比较字符串时忽略重音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:爪哇.比较字符串时忽略重音符号
 
				
         
 
            
        基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				