How would one use an # symbol inside a string in strings.xml?
<string name="twitter">#npike</string>
The XML editor gets rather angry:
error: Error: No resource type specified (at 'twitter' with value '#npike').
Use this instead :
<string name="twitter">\#npike</string>
I would suggest use unicode like \u0040 instead of '#' symbol. XML processing doesn't like special symbols. Here is list of special characters and it's unicode valuesSpecial characters and unicode values
Try escaping it with a backslash "\#". That works for quotes. You can't use XML entities in strings.xml, otherwise I would recommend that.
Related
In my strings.xml file I had this string:
<string name="lets_do_this">Let's Do This</string>
This gave me an error of:
Error:(897) Apostrophe not preceded by \ (in Let's Do This)
So I changed the string to this:
<string name="lets_do_this">Let\'s Do This</string>
But every time I build the project, the string keeps changing back to the first version for some reason and I keep getting that error without the ability to change the string. Why is this happening?
If it changes back, sounds like you changed the strings xml file that is located within the build folder, but you need to edit your own within res/values of the app module.
If you have an apostrophe (') in your string, you must either escape it with a backslash (\') or enclose the string in double-quotes ("").
see
Formatting and Styling - String Resources
<string name="lets_do_this">"Let's Do This"</string>
I am displaying Activity's Title from strings.xml file like this
setTitle(R.string.add_contact_title);
I have following string in strings.xml
<string name="add_contact_title">Anadir Contacto</string>
but i want to display title like Añadir Contacto instead of Anadir Contacto.
is there any way to do this within the strings.xml file rather than copying and pasting the characters from another source?
You can also use unicode using the \u escape sequence like this:
<string name="add_contact_title">A\u00F1adir Contacto</string>
See here for a list of common unicode latin characters: http://unicode-table.com/en/#latin-extended-b
You can use ñ
You can find all the HTML Special Characters in this page
Special Characters in Android & HTML
just replace the code where you want to put that character. :-)
Yes you can do that. You have to start the special character with &
i.e for your case it will be like ñ
<string name="add_contact_title">Añadir Contacto</string>
Just check the link which will convert ASCII into Unicode
ASCII to Unicode
and Unicode Reference
I am trying to insert a "#" symbol at the beginning of a text field in android. I have specified that in the string resources file as
<string name="email_ext">#xyz.com</string>
But it throws a compiler error - "No resource type specified (at 'email_ext' with value '#xyz.com'). Is there a way to fix this? I have tried to set that using the setter, but I have different resource files for different languages. Thanks in advance.
Add a \ before that #
<string name="email_ext">\#xyz.com</string>
The reason is that an # is the open symbol of any reference across Android resources. You could point to a color using #color/white, if you defined it. Because of this, the compiler tries to allocate a resource named xyz.com, but it actually has not a type defined (such as drawable, layout, id, string, etc). Hence the compiler error.
In fact, there is a cleaner version (found here):
<string name="email_ext">"#xyz.com"</string>
Using quotes looks less hacky
Add \
<string name="email_ext">\#xyz.com</string>
I recommend you to use \uxxxx for special characters, this is the table of unicodes http://jrgraphix.net/research/unicode_blocks.php?block=0, in your case you can use \u0040 for #symbol something like this:
<string name="email_ext">\u0040xyz.com</string>
Regards!
This gives me an error:
<string name="txt_urbeautiful">What...</string>
Replace "..." with ellipsis character (…, &&;#8230;)
So how do I encode 'et cetera...' in XML?
As the error says, you must replace ... by … :
<string name="txt_urbeautiful">What…</string>
"·"
That will represent .(dot ) in xml ,
XML does not use \ue*** notation. Character references, starting with &#, may be used, but they are mostly not needed. XML is usually used with UTF-8 character encoding, so that each character can be written as such.
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.