0

I have the byte representation of UTF8, e.g.

195, 156 for "Ü" (capital U Umlaut)

I need to create a string for display in JavaScript out of these numbers - everything I tried failed. No methode I found recognizes "195" as a UTF leading byte but gave mit "Ã".

So how do I get a string to display from my stream of UTF8 bytes?

4
  • How is 195 derived? Commented Jan 5, 2017 at 23:06
  • With the VBScript FileScriptingObject in HTA-Environment. Commented Jan 6, 2017 at 11:25
  • As the solution should also run from a server, I cannot use ADODB (which would do the job). Converting the result with decodeURIComponent(escape(Text)) works only for some characters. It looks like all characters with the second UTF8 byte were in the range of 128-159 cause decodeURIComponent to crash. Commented Jan 6, 2017 at 11:32
  • 1
    Possible duplicate of Decode UTF-8 with Javascript Commented Jan 7, 2017 at 23:07

1 Answer 1

1

You're working with decimal representations of the single byte components of the characters. For the example given, you have 195, 156. First, you have to converting to base 16's C3, 9C. From there you can use javascript's decodeURIComponent function.

console.log(decodeURIComponent(`%${(195).toString(16)}%${(156).toString(16)}`));

If you're doing this with a lot of characters, you probably want to find a library that implements string encoding / decoding. For example, node's Buffer objects do this internally.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.