I'm trying to store a fully qualified url, with also query params:
www.miosito.net?prova®=bis
but it's causing a problem because ® is similar to ® entity and android tell me that and html entity is not well written.
I need this because every locale uses a fully different set of url query param.
I tried with [[CDATA[.. ]] but this syntax disliked by xml parser.
The problem is not with &req but with & itself. For XML/HTML you would have to use & entity (or &), but for URLs you should rather URL-encode (see docs) strings, and in that case said & should be replaced with %26. So your final string should look like:
www.miosito.net?prova%26reg=bis
Store it like this:
<string name="my_url">"www.miosito.net?prova®=bis"</string>
Where & is the XML equivelant of the ampersand symbol &.
Percent encoding may do the trick: http://en.wikipedia.org/wiki/Percent-encoding
You'll basically have something like this: www.miosito.net?prova%26reg=bis
You can enclose your url in double quotes, something like :
<string name="my_url">"www.miosito.net?prova®=bis"</string>
This is a recommended way to enclose string resources in Android.
Update 1 : Have a look at the following link for more info :
http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
Update 2:
#WebnetMobile.com : Correct, indeed :)
'&' is being treated a special character by xml and enclosing in quotes doesn't work. I tried out
www.miosito.net?prova%26reg=bis
and it didn't work out either. I even tried enclosing it in quotes but still didn't work. Am I missing something ?
Meanwhile, the following does work :
<string name="my_url">www.miosito.net%1$sprova%2$sreg=bis</string>
and then in code :
Resources resources=getResources();
String url=String.format(resources.getString(R.string.my_url),"?","&") ;
The '%1$s' and '%2$s' are format specifiers, much like what is used in printf in C. '%1$s' is for strings, '%2$d' is for decimal numbers and so on.
Related
As mentioned in Emoji in strings.xml file? you need to use Unicode smileys like these:
https://apps.timwhitlock.info/emoji/tables/unicode
as HTML Entity but why didn't he mentioned how to convert them to HTML Entity.
I tried all kind of online converters like https://www.online-toolz.com/tools/text-html-entities-convertor.php but they don't convert stuff like U+1F601 to anything.
Can someone enlighten me?
This is easier than you might think: U+1F601 corresponds to 😁.
Slight modification to Henry's answer, You may use as follows.
<string name="hello_world">Hello world! 😁</string>
// this is using in decimal
But I have found that it is giving run time errors in Lollipop and below.
It works on marshmallow and above.
How can I use escape characters in XML?
The situation is, I am a new android developer, and I need a string which need to be printed in 2 lines (other wise no space). This string is in string.xml file. I need to use /n line break character to break the string, but I don't know how to do it in XML file. Please help.
See reference http://developer.android.com/guide/topics/resources/string-resource.html#String
line break symbol is \n
/n - is wrong.
and you can write it in xml like it is.
Example:
<string name="multiline_text">line 1.\nline2.</string>
I'm not familiar with Android development but have you checked out CDATA? Refer to this link.
Basically, you wrap your string value like so:
<![CDATA[string value]]>
You can use double quotes:
<string name="mystring">"One line\nAnother line"</string>
You can use the character entity
to indicate a linefeed.
I am extracting strings from KML file, if the string contains special character like !, #, #, ', " etc. its using codes like '
I am not able to extract entire string if it is like above, by calling getNodeValue(). It is terminating the string at special character.
<name>Continue onto Royal's Market</name>
If i extract the string i am getting only ""Continue onto Royal". I want entire string as
Continue onto Royal's Market.
How to achieve this ?? If anybody familiar with this please reply to this one.
Thanks
Your problem has nothing to do with KML but is general for XML parsning:
Don't use getNodeValue(), as there is no guarantee in DOM that text isn't actually split over several nodes.
Try using getTextContent() instead.
You might also have to replace entities, as in: node.getTextContent().replaceAll("'","'");
In general I wouldnt use DOM at all for extracting data.
I'd use the XmlPullParser as its simpler to work with - and parses faster.
I have a problem that I want to show a bulleted list contents which is resided in strings.xml file as an array elements. Then the problem is that how to convert the array elements in Html List format? Can any one suggest any solution regarding the same.
Thanks in advance
I just put the symbol directly into the strings.xml without any codes or anything:
<string name="msg_sms_no_note">• Notes and attachments will not be sent.</string>
There's a problem with the approach suggested by some of the answers in this thread of prepending the bullet unicode character (i.e. \u2022) to each of the Strings in the String array: You don't get proper indentation when one or more Strings in the String array span multiple lines. What you get is formatting as follows:
In order to get proper indentation, you're better using BulletSpan. In doing so, you'll get formatting as follows:
To use BulletSpan, you need to create a SpannableStringBuilder instance and append each String in your String array to this SpannableStringBuilder instance. As you append each String, call the setSpan(what:start:end:flags:) method on the SpannableStringBuilder instance passing in a BulletSpan instance for the what parameter. You can find an example of this in the appendBulletSpan(...) Kotlin extension function located here.
I think, the most elegant way of doing this is to load a WebView and put your string in it. this way, you use the common ul/li convention and you can style it at your leisure with CSS.
Use the unicode escape sequence "\u2022" in strings.xml
like so:
<string name="menu_new_trip_desc">View them in: \n\u2022 Table
i have made a string named info_data as follows
<string name="info_address">SVG Service Verlags GmbH & Co. KG\n
Schwertfegerstra?e 1-3\n
D-23556 L?beck\n
</string>
i am getting an xml error saying that
Multiple annotations found at this line:
- The entity name must immediately follow the '&' in the entity
reference.
- error: Error parsing XML: not well-formed (invalid token)
this error comes on the first line containing the &.
what is going wrong and how do i fix it.
thank you in advance.
You can't use the & sign. Try & (I haven't tested it but it may work).
I believe you will need to change the & to &.
<string
name="info_address">SVG Service Verlags GmbH & Co. KG\n Schwertfegerstra?e 1-3\n
D-23556 L?beck\n</string>
copy paste the code i have pasted.
use this string use & instead of &
While other answers about the ampersand may be correct, I don't think its just that.
This should be of some use.
Where an attribute value is a string, double backslashes ('\') must be used to escape characters — for example, '\n' for a newline or '\uxxxx' for a Unicode character.
You have \n, which may need to be \\n in addition to the change to the &