我剛剛注意到,SharedPreferences在存儲字符串時刪除回車符(\ r)。由於我不知道這件事的代價很高,我想知道它是否會刪除任何其他字符。換句話說,它是否使用某個字符集。SharedPreferences是否使用某個字符集?
SharedPreferences sp = activity.getSharedPreferences("preferences", Context.MODE_PRIVATE);
sp.edit().putString("Foo", "\r\nfoo").commit();
//After restarting the app
SharedPreferences sp = activity.getSharedPreferences("preferences", Context.MODE_PRIVATE);
String sFoo= sp.getString("Foo", ""); //returns "\nfoo", not "\r\nfoo"
謝謝你的情報。 UTF-8是否排除回車(\ r或0x0D)?爲什麼不是「\ r」映射到U + 0013? – Hong
它與UTF-8(它支持所有的Unicode字符)以及與XML有關的所有內容(這些都會使空白字符崩潰)無關。 –