2

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..
enter image description here

Here is the code of the app:
enter image description here

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.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
Omar
  • 7,835
  • 14
  • 62
  • 108
  • You can find your solution [at this link](http://stackoverflow.com/a/7962813/779408). Enjoy! :) – Bob Apr 18 '12 at 08:54

1 Answers1

0

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.

Ben Williams
  • 6,027
  • 2
  • 30
  • 54
  • I converted them to Char array, and there were some weird values.. They were the cause of the weird characters. Thanks – Omar Apr 27 '11 at 16:43
  • You can find your solution [at this link](http://stackoverflow.com/a/7962813/779408). Enjoy! :) – Bob Apr 18 '12 at 08:54
  • The weird characters are probably the Unicode [byte order mark, BOM](http://en.wikipedia.org/wiki/Byte_order_mark), which came about due to Microsoft. – hippietrail May 13 '13 at 11:35