如果字符串文本是从右到左书写的,是否可以在 android/Java 中识别?
我正在编写一个 Android 应用程序,我需要识别字符串中的文本是否是用 RTL(从右到左)语言编写的? 谢谢!
I'm writing an android application, and i need to recognize if the text i have in a String is written in a language that is RTL(right to left) ?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通过检查第一个字符是否在 RTL unicode 字符范围内来检查给定的字符串是否以 RTL 格式写入。
Check if the given String is written in RTL by checking if the very first character is within the range of RTL unicode characters.
根据android文档, Bidi 对象提供有关双向重新排序的信息用于创建它的文本。例如,为了正确显示阿拉伯语或希伯来语文本,这是必需的。这些语言本质上是混合方向的,因为它们从左到右对数字进行排序,而大多数其他文本从右到左进行排序。
According to the android document, A Bidi object provides information on the bidirectional reordering of the text used to create it. This is required, for example, to properly display Arabic or Hebrew text. These languages are inherently mixed directional, as they order numbers from left-to-right while ordering most other text from right-to-left.
两件事:
A/ http://pastebin.com/e276zn6y 确定字符脚本的 JavaScript 代码。应该给你一个想法。并借助:
B/ ftp://unicode.org/Public/UNIDATA/extracted /DerivedBidiClass.txt
[...] 被截断,
它为您提供了所有块的方向(显示 RTL 部分的开头),您可以计算出其余部分。
编辑:
您可能还想检查从右到左的格式字符 (U+20xx),请参阅 http://www.unicode.org/charts/PDF/U2000.pdf
Two things:
A/ http://pastebin.com/e276zn6y Javascript code to determine the script of a character. Should give you an idea. And with the help of:
B/ ftp://unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt
[...] truncated
which gives you the direction of all blocks (showing the beginning to the RTL section), you can figure out the rest.
EDIT:
You might also want to check for Right-To-Left format characters (U+20xx), see http://www.unicode.org/charts/PDF/U2000.pdf
Java 不是已经原生支持这个了吗?
Isn't this already natively supported in Java?
您可以使用 Bidi 类来检查
You can check that by using the Bidi class