how can I enter character “<” in strings.xml?

孤者浪人 提交于 2019-12-04 05:37:43

问题


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"> -&amp;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 -&lt; 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

&amp;

<![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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!