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

AndroidString

Android 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 =)

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

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 &#45; 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.

Reference

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&#8211;9d8c&#8211;11e1&#8211;93e3&#8211;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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionroibergView Question on Stackoverflow
Solution 1 - AndroidPhilView Answer on Stackoverflow
Solution 2 - AndroidTal WeissView Answer on Stackoverflow
Solution 3 - AndroidRajaReddy PolamReddyView Answer on Stackoverflow
Solution 4 - AndroidGanesh KatikarView Answer on Stackoverflow
Solution 5 - AndroidAmr AshrafView Answer on Stackoverflow
Solution 6 - AndroidMazView Answer on Stackoverflow
Solution 7 - AndroidHasan El-HefnawyView Answer on Stackoverflow