ASCII码=>字符串 [英] ASCII codes => string of characters

查看:97
本文介绍了ASCII码=>字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个ASCII码字符串:

I have the next string of the ASCII codes:

[-76,-96,-80,106,-58,106,-1,34,7,123,-84,101,51]

在这些代码值的字符字符串中转换它的最佳方法是什么? 这里有陷阱吗?

What is the best way to convert it in the string of the characters of these codes values? Are there any pitfalls here?

推荐答案

您需要将其转换为相应的字节数组,然后实例化new String(byteArray).

You need to turn it into a corresponding byte array and then instantiate new String(byteArray).

String [] strings = input.substring(1, input.length()-1).split(",");
byte[] bytes = new byte[strings.length];
int i = 0;
for (String s : strings) bytes[i++] = Byte.parseByte(s);
System.out.println(new String(bytes, "UTF-8"));

使用正确的字符编码代替"UTF-8".可以是CP-1250,ISO-8859-1或类似版本.

In place of "UTF-8" use your proper character encoding. It could be CP-1250, ISO-8859-1, or similar.

这篇关于ASCII码=>字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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