开发者

Problem with & and double quotes in my Android app

开发者 https://www.devze.com 2023-03-20 09:19 出处:网络
in my app I am facing following two problems I am trying to show some text from strings.xml file stored in res/values folder. The problem is whenever I enter the & it shows an error as follows:

in my app I am facing following two problems

  1. I am trying to show some text from strings.xml file stored in res/values folder. The problem is whenever I enter the & it shows an error as follows:

    Multiple annotations found at this line:

    - The entity name must immediately follow the '&' in the entity refere开发者_开发知识库nce.

    - error: Error parsing XML: not well-formed (invalid token)

When I remove it the error gets cleared. how to use such special characters in my app

  1. When I click a button in my app it hits an url and in return I am getting an return data as follows

    <img src="http://xxxxxxxxxxxxxxxxxxx/test.php%3Fcode_hash%3Da8c159f35af&amp;guid=ON"/>
    

I want to get this url removing the img src="

I tried using the replacewith("","");

But here I am unable to give the " within the double quotes.

How to solve the above issues?


In XML strings for & (ampersand) you need to use &amp; and quotes (single or double) need to be escaped,

<string name="with_amp">I, Me &amp; Myself</string>
<string name="with_quotes>Single quote \' and Double quotes \"</string>


Instead of & you have to use & check in the following statements

test&

<string name="url">http://xxxxxxxxxxxxxxxxxxx/test.php%3Fcode_hash%3Da8c159f35af&amp;guid=ON</string>


To use the symbol & in your strings.xml file, you need to use the appropriate XML character entity.
For ampersand, use &amp;.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号