0

Need to parse this file (mixed latin & arabic):

1|حِيمِ
2|الَمِينَ

The file was saved as UTF8 in notepad++, and put in android asset folder.
Expected result: for line1, the entries are "1" and "حِيمِ" (split by "|").

        AssetManager manager = context.getAssets();
        InputStream inStream = null;
        inStream = manager.open("file.txt");
        BufferedReader buffer = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));
        String line = "";
        while ((line = buffer.readLine()) != null) {
            String lineEnc = URLEncoder.encode(line, "UTF-8");
            String[] columns = lineEnc.split("%7C");
            if (columns.length>=3) {
                Toast toast = Toast.makeText(context, "Line: " + columns[0] + " and " + columns[1], Toast.LENGTH_LONG);
                toast.show();
            }
        }

Actual Result:
columns[0] = "1" ok, but
columns[1] = "%D8%AD%D9..." not Ok, expected "حِيمِ".
How to fix this, or is there better way? Please help. Thanks in advance.

Idn
  • 1
  • 1

1 Answers1

0

Solved, changing:

    while ((line = buffer.readLine()) != null) {
        String lineEnc = URLEncoder.encode(line, "UTF-8");
        String[] columns = lineEnc.split("%7C");

into

    while ((line = buffer.readLine()) != null) {
        String[] columns = line.split("\\|");
Idn
  • 1
  • 1