Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a "-" in string.xml file

Tags:

string

android

I need to be able to put a "-" in the string inside my strings.xml file.

My problem is that when I am putting my string which is "1261eba2-9d8c-11e1-93e3-40409e0f44a1", eclipse yells:

Multiple annotations found at this line: - Replace "-" with an "en dash" character (–, &;#8211;)

How can I fix this?

like image 535
roiberg Avatar asked May 14 '12 06:05

roiberg


People also ask

How do you add a space in a string in XML?

As already mentioned the correct way to have a space in an XML file is by using \u0020 which is the unicode character for a space.

How do you put and in string?

The reference to entity "Drop" must end with the ';' delimiter. How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.

Are dashes allowed in XML?

Element names cannot start with the letters xml (or XML, or Xml, etc) Element names can contain letters, digits, hyphens, underscores, and periods.


2 Answers

So, when you read the error message, your answer will be that you have to replace - with –. Then it should work fine =)

http://en.wikipedia.org/wiki/Dash

like image 55
Phil Avatar answered Sep 29 '22 12:09

Phil


The other answers are OK for when you want to display the string to the user. The user can't really tell the difference between a "real" dash and the unicode trickery.
But, if you really must have the dash (e.g. because that string is used as a password somewhere, or as a url key for an API) then you can just use this format:

<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">     <string name="EVA_API_KEY">3c42b725-5e20-41c8-982f-dee40be8a05b</string> </resources> 

The warning will be removed and the string can be read using the regular:

getResources().getString(R.string.EVA_API_KEY); 
like image 36
Tal Weiss Avatar answered Sep 29 '22 10:09

Tal Weiss