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?

Frank34
  • 79
  • 6
  • How is `195` derived? – guest271314 Jan 05 '17 at 23:06
  • With the VBScript FileScriptingObject in HTA-Environment. – Frank34 Jan 06 '17 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. – Frank34 Jan 06 '17 at 11:32
  • 1
    Possible duplicate of [Decode UTF-8 with Javascript](http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript) – JosefZ Jan 07 '17 at 23:07

1 Answers1

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.