gpt4 book ai didi

android - 在 txt 中查找 unicode 字符 - android

转载 作者:行者123 更新时间:2023-11-29 00:27:38 25 4
gpt4 key购买 nike

我正在阅读一个包含 unicode 字符的 txt 文件。我需要查找此文件中是否存在特定的 unicode 字符。到目前为止的代码如下,

    try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(getAssets().open("DistinctWords.txt"), "UTF-8"));

int i = 0;
String mLine = reader.readLine();
while ((mLine != null)) {
//process line
//unicode value taken from http://codepoints.net/U+0D85
if (mLine.contains("\u0D85")){
i++;
}
mLine = reader.readLine();

}

reader.close();
Log.i("tula", "Ayanna - " + String.valueOf(i));
} catch (IOException e) {
//log the exception
}

问题:“i”的值始终为“0”。当我从记事本打开同一个文本文件时,我可以看到这封信,但我的代码找不到它。

最佳答案

正如 TronicZomB 所说,我认为您需要寻找实际角色,例如:

while ((mLine != null)) {
//process line
if (mLine.contains("අ")){
i++;
}
mLine = reader.readLine();
}

您需要使用能够处理正确编码的编辑器:

  • Windows 上的记事本允许您在文件上指定 UTF-8 编码,但您必须将文件的编码设置为 ANSI 的 UTF-8。
  • 在 mac OS-x 上,您可以使用 TextEdit。在首选项中,使用打开和保存选项卡,您可以设置文档编码。
  • 在 Linux 上 StarOffice 应该可以工作,但我没有使用过它。

关于android - 在 txt 中查找 unicode 字符 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18221828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com