kbz
kbz

Reputation: 1006

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. I understand how this works, but I don't understand the regex that I would need to use to complete this task.

Example:

"108108108108"

108 represents the character "l", so the output would be: llll

Upvotes: 0

Views: 857

Answers (1)

flotothemoon
flotothemoon

Reputation: 1892

Character.toString((char) i);

i is the ASCII value of the character.

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?

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.

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.

Upvotes: 1

Related Questions