问题
I want to enter string " -< "
in strings.xml
file in eclipse, the string has character <
and I couldn't add it to xml file without error! I even tried to escaping by \
character:
<string name="search_target_arrow"> -\< </string>
or enclosing it between ""
as below:
<string name="search_target_arrow">" -< "</string>
but none worked. Then finally with help of kind users here I found that this would be the correct way to enter such chars in xml:
<string name="search_target_arrow"> -&lt; </string>
but now when I get this resource in my code:
getResources().getString(R.string.search_target_arrow);
and set it to a TextView, It shows -<
on screen! How to get original character by code? should I do something related to HTML?!
回答1:
If you are using eclipse then right click on strings.xml & open it with "Android Common XML Editor" & add from there it will handle escaping for you.
回答2:
Two options
&
<![CDATA[&this is my> string and I <can put all the strange symbols I want inside]]>
回答3:
In the graphical editor (i guess the "Recources" tab), you can type any symbol into the value box, and it'll automatically put the appropriate characters in the xml. So that's good if you don't want to look the codes up.
来源:https://stackoverflow.com/questions/12250690/how-can-i-enter-character-in-strings-xml