James
James

Reputation: 14091

Escape " " in Text in TextView

I have a textView and I am pasting s string as it's text and in which I have some "double quote characters" How can I escape these characters.

Upvotes: 10

Views: 7725

Answers (2)

Jacob Ras
Jacob Ras

Reputation: 5969

Backslashing double quotes will not work in a XML layout. You should use the HTML-code (quot), like this:

<TextView android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:text="Here goes my &quot;escaped&quot; text!" />

The above code will display a TextView containing:

Here goes my "escaped" text!

XML has 5 of these predifined entities:

&quot;   "
&amp;    &
&apos;   '
&lt;     <
&gt;     >

Upvotes: 17

anon
anon

Reputation:

Just use the replace method of the String class: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replace(char,%20char)

Use something like this for you String and then pass this String to the TextView:

myString.replace("\"", "");

Upvotes: 3

Related Questions