开发者

Escape "@" character in Android

I'm looking for a way to escape the开发者_Python百科 "@" symbol at the start of a string, in Android strings.xml resource. I'm continuously getting compilation errors and the layout builder in Eclipse refuses to work :(. Does anyone know how?


The character scape depends of each one, the android documentation provides this table in https://developer.android.com/guide/topics/resources/string-resource

Escape "@" character in Android


On the Android Documentation website, it says to use a double backslash to escape characters.

< string name="twitter">\\@mytwitter< /string>


You should use the "\" before "@". eg

escaped\@ 

:-)


According to the Android developer guide, you'll have to escape certain characters with a backslash \ or enclosing the whole string with double quotes " ". Only if the string starts with @, it has to be escaped.

Backslash:
<string name="twitter">\@user</string>
<string name="email">user@domain</string>

Double quotes:
<string name="twitter">"@user"</string>
<string name="email">user@domain</string>

Other characters that needs to be escaped are < > & ' " ?


Space between backslash and slash worked for me, thx! <string name="first">1\ /4</string>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜