简体   繁体   English

如何将ascii值的字符串转换回其String / Character值?

[英]How can I convert a String of ascii values back to their String/Character values?

Given a String of numerical ascii values, how can I convert these back to their original characters to generate a String. 给定一个数字ascii值的字符串,我如何将它们转换回其原始字符以生成字符串。 I understand how this works, but I don't understand the regex that I would need to use to complete this task. 我了解这是如何工作的,但我不了解完成该任务需要使用的正则表达式。

Example: 例:

"108108108108" “108108108108”

108 represents the character "l", so the output would be: llll 108代表字符“ l”,因此输出将是:llll

Character.toString((char) i); Character.toString((char)i);

i is the ASCII value of the character. i是字符的ASCII值。

Character.toString((char) 108); Character.toString((char)108); would be 'i'. 会是“我”。

You might want to take a look at this: How to convert ASCII code (0-255) to a String of the associated character? 您可能需要看一下: 如何将ASCII码(0-255)转换为关联字符的字符串?

But if you dont know if 1087 means 108 and 7 or 10 and 87, like if you cant be sure that the values are saved like 001 and 002 for 1 and 2, you can't. 但是,如果您不知道1087是表示108和7还是10和87,就像您不能确定将值保存为001和002这样表示1和2一样,则不能。

The function would have to be able to differbetween those cases, but however it doesn't know if you mean 10 and 87 or 108 and 7 or 1 and 87. 该函数必须能够在这些情况之间有所区别,但是它不知道您的意思是10和87还是108和7或1和87。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM