我怎么知道我的字符串包含变音符号? [英] How can i get know that my String contains diacritics?
本文介绍了我怎么知道我的字符串包含变音符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如 -
text =Československáobchodníbanka;
文本字符串包含Č,á等变音符号。
写一个函数,其中i将传递此字符串Československáobchodníbanka和函数将返回true如果字符串包含diacritics否则
。
$ b b
我必须处理变音符号和包含不分别在Az或az范围内的字符的字符串。
1)如果String包含变音符,那么我必须做一些XXXXXX。
2)如果String包含除A-Z或a-z之外的字符,并且不包含变音符号,则执行一些其他操作YYYYY。
我不知道该怎么做。
á的代码,但是结果可能与<$ d c $ c> a 和
组合标记 - '
。 java.text.Normalizer ,如下所示:
public static boolean hasDiacritics(String s){
//将任何á分解为a和combine-'。
String s2 = Normalizer.normalize(s,Normalizer.Form.NFD);
return s2.matches((?s)。* \\p {InCombiningDiacriticalMarks}。*);
// return!s2.equals(s);
}
For Example -
text = Československá obchodní banka;
text string contains diacritics like Č , á etc.
I want to write a function where i will pass this string "Československá obchodní banka" and function will return true if string contains diacritics else false
.
I have to handle diacritics and string which contains character which doesn't fall in A-z or a-z range separately.
1) If String contains diacritics then I have to do some XXXXXX on it.
2) If String contains character other than A-Z or a-z and not contains diacritics then do some other operations YYYYY.
I have no idea how to do it.
解决方案
One piece of knowledge: in Unicode there exists a code for á
but the same result one may get with an a
and a combining mark-'
.
You can use java.text.Normalizer, as follows:
public static boolean hasDiacritics(String s) {
// Decompose any á into a and combining-'.
String s2 = Normalizer.normalize(s, Normalizer.Form.NFD);
return s2.matches("(?s).*\\p{InCombiningDiacriticalMarks}.*");
//return !s2.equals(s);
}
这篇关于我怎么知道我的字符串包含变音符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文