简体   繁体   English

Android字节转字符串字符集

[英]Android byte to string charset

I have a problem with the charset convertion: 我对字符集转换有疑问:

I have got messages from udp server and I get the data like this: 我收到了来自udp服务器的消息,并且得到了如下数据:

byte[] adress= new byte [42];

After I try to displayed to textview : 在我尝试显示到textview之后:

String str_adress= new String(adress,"UTF-8");

Instead of "ő" I got just "?" 我得到的不是“原来的”,而是“?”。

How can I solve that? 我该如何解决?

The UTF-8 bytes for ő are c5 91 . ő的UTF-8字节为c5 91

As

Log.v(TAG, new String(new byte[] { (byte) 0xc5, (byte) 0x91 }, "UTF-8"));

outputs 输出

ő

I think you looked in the wrong place for the problem. 我认为您在错误的地方找到了问题。 It's coming from somewhere else, like reading the udp message maybe. 它来自其他地方,例如可能阅读udp消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是String(byte [],charset)内存有效的 - is String(byte[], charset) memory efficient 使用byte []和charset的构造函数创建字符串对象 - String object creation using constructor of byte[] and charset 在不使用String或Charset的情况下,将数组字符串转换为UTF-8中的字节数组 - Char array to byte array in UTF-8 without using String or Charset 从无效(对于字符集)byte []进行转换时,Java String的行为(安全)? - Behavior (safety) of Java String when converting from invalid (for the charset) byte[]? 在 Android 中将字节转换为字符串 - Converting a byte to a String in Android 使用 UTF-8 字符集时,为什么在链中 byte[] → String → byte[] 输入和输出不同? - Why in chain byte[] → String → byte[] input and output differ when using UTF-8 charset? 使用特定的字符集将byte []转换为String时,避免创建“new”String对象 - Avoid creating 'new' String objects when converting a byte[] to String using a specific charset 将Java字节读取为CharSet - Reading Java byte's as CharSet Android:字节数组到十进制字符串 - Android: byte array to decimal string JavaScript等效于Java的Charset / String类组合,用于解码字节数组 - JavaScript equivalent to Java's Charset/String class combination for decoding byte arrays
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM