问题
I'm developing an app with Arabic text in it.. My phone supports Arabic so the text gets displayed correctly.. the weird problem is that: if I copy an Arabic text that i want from a.txt file and put it into an EditText, the EditText displays weird characters, but if I write the SAME text manually (not copy-paste), the text gets displayed normally!!
Here is a picture showing what I mean, the first EditText is the text I wrote manually, and the second is the text I copy-pasted from the .txt file..
Here is the code of the app:
xml file:
<?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>
I hope you get what I mean, since it wasnt easy to explain this weird (stupid) problem. Thanks.
回答1:
If you line the setText up, the second is longer than the first, which means it almost certainly contains characters that look like spaces but are actually something else; try UTF-8 encoding the string and comparing them block by block.
来源:https://stackoverflow.com/questions/5804622/certain-arabic-text-gets-incorrectly-shown-while-other-arabic-text-gets-showed-n