Skip to content Skip to sidebar Skip to footer

Encode/decode Hex To Utf-8 String

Working on web application which accepts all UTF-8 character's including greek characters following are strings that i want to convert to hex. Following are different language stri

Solution 1:

Javascript works with 16-bit unicode characters, therefore charCodeAt might return any number between 0 and 65535. When you encode it to hex you get strings from 1 to 4 chars, and if you simply concatenate these, there's no way for the other party to find out what characters have been encoded.

You can work around this by adding delimiters to your encoded string:

functionencode(string) {
     return string.split("").map(function(c) {
        return c.charCodeAt(0).toString(16);
     }).join('-');
}

alert(encode('größe Εγκυκλοπαίδεια 维'))

Post a Comment for "Encode/decode Hex To Utf-8 String"