3

In the below posted entry in the strings.xml, I would like to save a url and it includes & sign. this sign is not recognized...How to save the link as entry in strings.xml..the & sign is not recognized

url

    <string name="BASE_URL">https://en.wikipedia.org/w/api.php? 
    action=query&format=json&list=search&srsearch=Trump</string>
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • Possible duplicate of [How can I write character & in android strings.xml](https://stackoverflow.com/questions/3053062/how-can-i-write-character-in-android-strings-xml) – sanoJ Jul 09 '19 at 08:00

4 Answers4

0

Just replace each & with &amp;

<string name="BASE_URL">https://en.wikipedia.org/w/api.php? 
    action=query&amp;format=json&amp;list=search&amp;srsearch=Trump</string>

There are some other characters that can be replaced:

> -- &gt;
< -- &lt;
" -- &quot;
' -- &apos;
Jaime Suarez
  • 660
  • 4
  • 11
0

You need to escape them, in this case & becomes &amp; in the strings.xml file

Ricardo
  • 9,136
  • 3
  • 29
  • 35
0

Replace your & with %26

So your final URL will become

https://en.wikipedia.org/w/api.php?action=query%26format=json%26list=search%26srsearch=Trump

OR

Enclose your url in double quotes

<string name="BASE_URL">"https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=Trump"</string>
Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
0

Since

&

is a special character, it has to be replaced with

%26

This should be your final string as you require it:

 <string name="BASE_URL">https://en.wikipedia.org/w/api.php?
    action=query%26format=json%26list=search%26srsearch=Trump</string>
E_net4
  • 27,810
  • 13
  • 101
  • 139
Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20