gpt4 book ai didi

java - 字符串编码 TextView.setText()

转载 作者:行者123 更新时间:2023-11-29 19:06:21 25 4
gpt4 key购买 nike

在 TextView 中设置文本时,字符“ù”未被正确解释。这是我的代码:

TextView tv = new TextView(context);
String s;
byte[] bytes;
s = "dgseùeT41ù";
bytes = s.getBytes("ISO-8859-1");
tv.setText(new String(bytes));

我不知道我哪里失败了。谢谢支持

最佳答案

您使用了 "ISO-8859-1" 但 java 默认使用 UTF-8 所以要么在创建字符串时定义字符集

From docs

Case mapping is based on the Unicode Standard version specified by the Character class and A String represents a string in the UTF-16 format

所以

bytes = s.getBytes("ISO-8859-1");
tv.setText(new String(bytes,"ISO-8859-1"));

或者根本不使用它

bytes = s.getBytes();
tv.setText(new String(bytes));

关于java - 字符串编码 TextView.setText(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47083800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com