如何在android strings.xml中編寫字符&

我在strings.xml文件中寫了如下內容: php

<string name="game_settings_dragNDropMove_checkBox">Move by Drag&Drop</string>

我收到如下錯誤: 數組

The reference to entity "Drop" must end with the ';' delimiter.

我怎樣才能在strings.xml中寫字符? 編碼


#1樓

您能夠在此頁面中找到全部HTML特殊字符http://www.degraeve.com/reference/specialcharacters.php只需替換要放置該字符的代碼便可。 :-) spa


#2樓

編碼: .net

&amp;

#3樓

對於特殊字符,我一般使用Unicode定義,對於'&'例如:\\ u0026若是我是正確的。 這是一個很好的參考頁面: http//jrgraphix.net/research/unicode_blocks.php?block = 0 code


#4樓

也能夠將字符串的內容放入XML CDATA,就像Android Studio在Extract string resource時爲您作的那樣xml

<string name="game_settings_dragNDropMove_checkBox"><![CDATA[Move by Drag&Drop]]></string> ci


#5樓

這可能很老了。 但對於那些尋找快速代碼的人。 unicode

public String handleEscapeCharacter( String str ) {
    String[] escapeCharacters = { "&gt;", "&lt;", "&amp;", "&quot;", "&apos;" };
    String[] onReadableCharacter = {">", "<", "&", "\"\"", "'"};
    for (int i = 0; i < escapeCharacters.length; i++) {
        str = str.replace(escapeCharacters[i], onReadableCharacter[i]);
    } return str;
 }

處理轉義字符,您能夠在各自的數組上添加字符和符號。 字符串

-乾杯

相關文章
相關標籤/搜索