是否共享preferences使用特定的字符集? [英] Does SharedPreferences use a certain character set?

查看:157
本文介绍了是否共享preferences使用特定的字符集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚才注意到,共享preferences存储字符串时删除回车(\\ r)的。由于这是相当昂贵的我不知道这一点,我想知道,如果它删除任何其他字符。换句话说,它使用某个字符集。

 共享preferences SP = activity.getShared preferences(preferences,Context.MODE_PRIVATE);
。sp.edit()putString(富,\\ r \\ nfoo)提交()。//后重新启动应用程序
共享preferences SP = activity.getShared preferences(preferences,Context.MODE_PRIVATE);
字符串sFoo = sp.getString(富,); //返回\\ nfoo,而不是\\ r \\ nfoo


解决方案

早上好

这是更坏:如果您存储字符串为\\ r到共享preF,杀戮和重新启动应用程序后,从共享preF值将变成\\ n

这是我们敬爱的Andr​​oid平台的另一个错误,很讨厌...

干杯

I have just noticed that SharedPreferences removes carriage return (\r) when storing a string. Since it was quite costly for me to not know this, I would like to know if it removes any other characters. In other words, does it use a certain character set.

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"

解决方案

Good morning,

It is even worst: if you store the String "\r" into SharedPref, after killing and restarting application, the value from SharedPref will become "\n".

Another bug from our beloved Android platform, very annoying...

Cheers

这篇关于是否共享preferences使用特定的字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆