Java分裂给出了阿拉伯字符的相反顺序

时间:2013-11-10 00:34:29

标签: java android intellij-idea split arabic

我使用IntelliJ 12 IDE在java(android)中使用\\|拆分以下字符串。

enter image description here

除了最后一部分,一切都很好,不知何故,分裂以相反的顺序拾取它们:

enter image description here

正如您所看到的那样,真实定位34,35,36是正确的,并且根据字符串,但当它以错误的顺序被挑选到split part no 5时,36,35,34 ... < / p>

我能以任何方式让他们按照正确的顺序吗?

我的代码:

public ArrayList<Book> getBooksFromDatFile(Context context, String fileName)
{
    ArrayList<Book> books = new ArrayList<Book>();

    try
    {
        // load csv from assets
        InputStream is = context.getAssets().open(fileName);

        try
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));

            String line;
            while ((line = reader.readLine()) != null)
            {
                String[] RowData = line.split("\\|");
                books.add(new Book(RowData[0], RowData[1], RowData[2], RowData[3], RowData[4], RowData[5]));
            }
        }
        catch (IOException ex)
        {
            Log.e(TAG, "Error parsing csv file!");
        }
        finally
        {
            try
            {
                is.close();
            }
            catch (IOException e)
            {
                Log.e(TAG, "Error closing input stream!");
            }
        }
    }
    catch (IOException ex)
    {
        Log.e(TAG, "Error reading .dat file from assets!");
    }

    return books;
}

2 个答案:

答案 0 :(得分:1)

字符串中的字符应始终采用语言顺序,无论它们是从右到左还是从左到右的字符。所以我们应该看到[34] ='1',[35] =' - ',[36] ='7'。渲染引擎要使用正确的从右到左或从左到右的布局来显示它们。

答案 1 :(得分:0)

在Unicode世界中,有强弱的角色。这些是弱字符列表:

 "\\", "/", "+", "-", "=", ";", "$" 

它们被称为“弱”字符,因为它们不包含任何方向信息。因此,由软件来决定放置这些“弱”字符的方向more info here。 要解决此问题,您需要设置Directional Formatting,例如:

RightToLeftEmbedding + weakCharacter + PopDirectionalFormatting

使用这些常数值

 char RightToLeftEmbedding = (char)0x202B;
 char PopDirectionalFormatting = (char)0x202C;