如何在 string.xml 文件中放入“-”

我需要能够把一个“-”在字符串内的 strings.xml文件。

我的问题是,当我放置字符串 "1261eba2-9d8c-11e1-93e3-40409e0f44a1"时,eclipse 会喊:

在这一行可以找到多个注释: - 将“-”替换为“ en 破折号”字符(- , )

我该怎么补救?

73336 次浏览

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

This called escape character. ( \ )

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

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.

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);

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...

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.

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