无法替换阿拉伯语字符

a7qyws3x  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(194)

所以我试图用特定的数字来代替阿拉伯字符,但问题是阿拉伯字符会根据它们在句子中的位置而变化,从而破坏了代码。例如,字母“م" 是“ﻣ" 当放在句首时ﻤ" 在中间和“ﻢ" 最后。
有人知道怎么解决这个问题吗?

File text = new File("C:/Users/LENOUVO/Desktop/AR_ar.json");
    String oldContent = "";
    BufferedReader reader = new BufferedReader(new FileReader(text));

    String line = reader.readLine();

    while (line != null) {
        oldContent = oldContent + line + System.lineSeparator();
        line = reader.readLine();
    }

    reader.close();

    String newContent = oldContent.replaceAll("ا", "{00311}");
    newContent = newContent.replaceAll("أ", "{00312}");
    newContent = newContent.replaceAll("ﺑ", "{00313}");
    newContent = newContent.replaceAll("ﻟ", "{00314}");
    newContent = newContent.replaceAll("ﺒ", "{00315}");
    newContent = newContent.replaceAll("ﺮ", "{00316}");
    newContent = newContent.replaceAll("ﻌ", "{00317}");
    newContent = newContent.replaceAll("ﻴ", "{00318}");
    newContent = newContent.replaceAll("ﺔ", "{00319}");
    newContent = newContent.replaceAll("ر", "{00320}");
    newContent = newContent.replaceAll("ﻠ", "{00321}");
    newContent = newContent.replaceAll("ﻐ", "{00322}");

    FileWriter writer = new FileWriter(text);
    writer.write(newContent);

    writer.close();
}

输入文本:
العربية
输出文本:
{00311}لع{00320}بية

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题