Can't Replace Arabic Characters

Viewed 86

So I'm trying to replace Arabic characters with specific numbers, but the problem is that Arabic characters change depending on where they are placed in the sentence thus breaking the code. For instance, the letter "م" is "ﻣ" when placed at the beginning of the sentence, "ﻤ" in the middle and "ﻢ" at the end.

Does anyone know how to fix this?

        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();
}

Inputted text:

العربية

Outputted text:

{00311}لع{00320}بية

0 Answers
Related