How to put a "-" in string.xml file
AndroidStringAndroid Problem Overview
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?
Android Solutions
Solution 1 - Android
So, when you read the error message, your answer will be that
you have to replace -
with –
. Then it should work fine =)
Solution 2 - Android
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);
Solution 3 - Android
Use back slash ( \ ) in front of every special character. like me&android.
This called escape character. ( \ )
Solution 4 - Android
For hyphen use (-) (-)...
<string name="abc">Welcome - Bro...</string>
and For more symbol use below link
http://www.degraeve.com/reference/specialcharacters.php
Enjoy...
Solution 5 - Android
> The dash is a punctuation mark that is similar to a hyphen or minus sign, but differs from both of these symbols primarily in length and function. The most common versions of the dash are the en dash (–) and the em dash (—), named for the length of a typeface's lower-case n and upper-case M respectively.
Just replace -
with –
because when you type a dash on the keyboard, XML reads dash as minus, that's all.
Solution 6 - Android
You probably have this:
<string name="test1">1261eba2-9d8c-11e1-93e3-40409e0f44a1</string>
But you need either one of these:
<string name="test2">1261eba2–9d8c–11e1–93e3–40409e0f44a1</string>
<string name="test3">1261eba2–9d8c–11e1–93e3–40409e0f44a1</string>
In the second one the - is replaced by a –. It's hard to tell the difference visually.
Solution 7 - Android
The quick fix shortcut in Eclipse is Ctrl
+ 1
by default and in Android Studio is Alt
+ Enter
by default.