如果字符串包含 Char[] 数组,则在该字符串中进行搜索的代码?
我正在开发一个应用程序,该应用程序具有以下功能:如果文本 (searchString
) 位于 .txt 文件中(.txt 文件也是阿拉伯语言),则可以用阿拉伯语搜索该文本。
由于 Android 不支持 100% 阿拉伯语,因此 String.indexof()
无法正常工作。因此,我想,我会将 searchString
放入 Char[]
数组中,而不是比较整个单词,而是比较每个字符。因此,我将 searchString
放入 char[]
中,并开始将数组与字符串进行比较。
是否可以在任何地方使用搜索 char[] 中的序列的代码数组转换成字符串?
示例:
char[]={t,e,s,t} String1{qqwtestq} String2{qwqtqwe} -> String1:TRUE String2:FALSE
谢谢
I'm developing an app that has a feature to search a text (searchString
) in Arabic language if it is in a .txt file (.txt file is also in Arabic language).
Since Android doesn't support Arabic 100%, String.indexof()
doesn't work properly. So, I thought, I would put the searchString
into a Char[]
array and instead of comparing the whole word, I compare every character. So I put the searchString
into a char[]
and start comparing the array to the String
Is it available anywhere a code that searches if the sequence that is in the char[] array is into a String?
example:
char[]={t,e,s,t} String1{qqwtestq} String2{qwqtqwe} -> String1:TRUE String2:FALSE
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(4)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
indexOf
和contains
不使用任何类型的字符编码,例如,您可以使用字符编码中未使用的字符。即这些函数会忽略它。所有 String.indexOf() 和 contains 都是比较字符。我不确定您期望 100% 阿拉伯语支持是什么样的行为。这是 indexOf()/contains() 的简化版本 打印
您
能提供一个此方法不起作用的示例吗?
编辑:此测试检查每个可能的字符以查看 indexOf 的行为是否符合预期。即对于每个可能的字符都相同。
没有发现任何差异。
indexOf
andcontains
don't use character encoding of any sort and you can use characters which are not used in your character encoding for example. i.e. it is ignored for these functions.All String.indexOf() and contains do is compare character for character. I am not sure what behaviour you are expecting for 100% Arabic support. Here is a simplified version what the indexOf()/contains() does
Prints
Can you provide an example where this method doesn't work?
EDIT: This test checks every possible character to see if indexOf behaves as expected. i.e. the same for every possible character.
Finds no discrepancies.