我正在编写一个Android应用程序,我需要识别我在String中的文本是用RTL语言(从右到左)编写的? 谢谢!
答案 0 :(得分:5)
通过检查第一个字符是否在RTL unicode字符范围内,检查给定的String是否是用RTL写的。
public static boolean checkRtl ( String string ) {
if (TextUtils.isEmpty(string)) {
return false;
}
char c = string.charAt(0);
return c >= 0x590 && c <= 0x6ff;
}
答案 1 :(得分:1)
两件事:
A / http://pastebin.com/e276zn6y用于确定角色脚本的Javascript代码。应该给你一个想法。并借助:
B / ftp://unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt
# Bidi_Class=Right_To_Left
0590 ; R # Cn <reserved-0590>
05BE ; R # Pd HEBREW PUNCTUATION MAQAF
05C0 ; R # Po HEBREW PUNCTUATION PASEQ
05C3 ; R # Po HEBREW PUNCTUATION SOF PASUQ
05C6 ; R # Po HEBREW PUNCTUATION NUN HAFUKHA
05C8..05CF ; R # Cn [8] <reserved-05C8>..<reserved-05CF>
05D0..05EA ; R # Lo [27] HEBREW LETTER ALEF..HEBREW LETTER TAV
[...]截断
它为您提供所有块的方向(显示RTL部分的开头),您可以弄清楚其余部分。
编辑: 您可能还想检查从右到左格式的字符(U + 20xx),请参阅http://www.unicode.org/charts/PDF/U2000.pdf
答案 2 :(得分:0)
这在 Java 中不是已经被原生支持了吗?
// LIST OF ALL SCHOOL
Map schoolList;
// LIST OF FEATURED SCHOOL FROM FEATURED/RECOMMEND
List featuredSchool = [];
// LIST OF CATEGORIES FROM INFORMATION CATEGORIZE/LIST
List categories = [];
void homeCard() {
for (String category in categories) {
// ADD TO LIST
for (String school in featuredSchool) {
if (schoolList[category][school] as String != null) {
featuredCard.add(
// CARD TEMPLATE
HomeCard(
// FROM UNIVERSITY/INFORMATION/SCHOOL/[RECOMMENDED SCHOOL]/'TITLE'
name: schoolList[category][school]['title'] as String,
// FROM UNIVERSITY/INFORMATION/SCHOOL/[RECOMMENDED SCHOOL]/'CATEGORY'
category: schoolList[category][school]['category'] as String,
// FROM UNIVERSITY/INFORMATION/SCHOOL/[RECOMMENDED SCHOOL]/'IMGCARD'
networkImage:
NetworkImage(schoolList[category][school]['imgcard'] as String),
// CARD FUNCTION
function: () {},
),
);
String name = schoolList[category][school]['title'] as String;
print(name);
}
}
}