90

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?

zrajm
  • 1,361
  • 1
  • 12
  • 21
roiberg
  • 13,629
  • 12
  • 60
  • 91

7 Answers7

124

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

JJD
  • 50,076
  • 60
  • 203
  • 339
Phil
  • 2,396
  • 2
  • 18
  • 15
  • 4
    This is OK when you just want to display the string to the user. The user can't really tell that you are "cheating" with a similar looking unicode character. If you just want to use the regular dash see this answer: http://stackoverflow.com/a/10895509/78234 – Tal Weiss Mar 26 '14 at 15:09
  • 2
    I think that code is for endash, not a regular hyphen. – John61590 Sep 14 '16 at 17:19
  • Ya that's an en-dash not a hyphen https://www.thepunctuationguide.com/en-dash.html – Blundell Jun 25 '20 at 11:39
88

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);
Tal Weiss
  • 8,889
  • 8
  • 54
  • 62
  • 10
    One tip: you might want to put the tools:ignore="TypographyDashes" part into just those tags that really need the real dash. – Dan J Feb 25 '13 at 06:25
  • 1
    For some reason it only worked for me when I put the ignore on the string i'm using. Thanks for the answer I found out it was the wrong dash, but how to get it to work wasn't as straightforward. – Mathijs Segers Jun 17 '14 at 08:49
  • 1
    I was trying to launch the phone dialer for 9-1-1 and your answer was the key for that. Thanks! – Roisgoen Mar 27 '15 at 21:41
15

Use back slash ( \ ) in front of every special character. like me\&android.

This called escape character. ( \ )

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
5

For hyphen use (&#45) (-)...

<string name="abc">Welcome &#45; Bro...</string>

and For more symbol use below link

http://www.degraeve.com/reference/specialcharacters.php

Enjoy...

Ganesh Katikar
  • 2,620
  • 1
  • 26
  • 28
4

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.

Amr Ashraf
  • 315
  • 4
  • 14
1

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.

Maz
  • 764
  • 5
  • 5
  • 1
    Be careful though: if you change these symbols in a URL it might stop working (mine did). – Dan J Feb 25 '13 at 06:22
  • I want to replace a short dash symbol (n-dash) with an escaped sequence. But `–` looks like its the escape sequence for the long dash symbol (m-dash). – Etienne Lawlor Jun 10 '16 at 18:52
0

The quick fix shortcut in Eclipse is Ctrl + 1 by default and in Android Studio is Alt + Enter by default.

Hasan El-Hefnawy
  • 1,249
  • 1
  • 14
  • 20