encoding - encode string as utf-16 to base64 in javascript -
i'm struggling find resources on online, concerning. i've been reading ucs-2 , utf-16 woes, can't find solution.
i need value input:
var val = $('input').val()
and encode base64, treating text utf-16, so:
this test
becomes:
daboagkacwagagkacwagageaiab0aguacwb0aa==
and not below, treating utf-8:
dghpcybpcybhihrlc3q=
your data, once read javascript, in encodingless numerical format (strictly speaking, has in unicode normalised form c, unicode series of identifying numbers each glyph in unicode lexicon. it's encoding-less). so: if need data encoded utf-16 byte sequence, so, base64 encode that.
but here's fun part: utf-16 need? little or big endian? or without bom? utf-16 inconvenient encoding format (we're not going touch ucs-2. it's obsolete. has been long time).
what should need text value html element, base64 encode value, , have whatever receives data unpack utf8; don't try make javascript more work has to. presume you're sending data server or something, in case: server language way more elaborate javascript, , can unpack text in million different encodings built-in functions. use that. don't solve y x.
Comments
Post a Comment