2011-04-27 87 views
2

我正在開發一個阿拉伯語文本應用程序..我的手機支持阿拉伯語,所以文本顯示正確..奇怪的問題是,如果我複製一個阿拉伯文本,我想從a.txt文件,並把它到EditText中,EditText顯示奇怪的字符,但是如果我手動寫入SAME文本(而不是複製粘貼),文本將正常顯示!
這裏是在我的意思的圖片,第一個是的EditText我手動寫的文字,第二個是我複製粘貼文本從.txt文件..
enter image description here某些阿拉伯文字得到錯誤顯示,而其他阿拉伯文字得到正常顯示?

這裏的代碼應用:
enter image description here

XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:orientation="vertical"> 
    <EditText android:text="EditText" android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText> 
    <EditText android:text="EditText" android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText> 
</LinearLayout> 

我希望你明白我的意思,因爲它不是很容易解釋這個奇怪的(愚蠢)的問題。謝謝。

+0

您可以在[此鏈接]找到您的解決方案(http://stackoverflow.com/a/7962813/779408)。請享用! :) – breceivemail 2012-04-18 08:54:26

回答

0

如果您將setText向上排列,則第二個比第一個更長,這意味着它幾乎肯定包含看起來像空格但實際上是別的東西的字符;嘗試使用UTF-8對字符串進行編碼並逐個比較它們。

+0

我將它們轉換爲Char數組,並且存在一些奇怪的值。它們是奇怪字符的原因。謝謝 – Omar 2011-04-27 16:43:25

+0

您可以在[此鏈接]找到您的解決方案(http://stackoverflow.com/a/7962813/779408)。請享用! :) – breceivemail 2012-04-18 08:54:33

+0

奇怪的字符可能是由於Microsoft而產生的Unicode [字節順序標記,BOM](http://en.wikipedia.org/wiki/Byte_order_mark)。 – hippietrail 2013-05-13 11:35:47