javascript - Working with characters based on their UTF-8 hex codes -


i'm working on read user's text messages , export them csv file, can download. messages being retrieved third-party web interface—i using js grab html of each message , compiling needed. content of each message added variable which, once message gathered, given new blob, downloaded.

the problem having that, in web interface, emoji represented images, rather characters. thus, when writing message containing emoji file, result so:

"blah blah blah <img height="18px" width="18px" class="emoji adjustedspriteformessagedisplay spriteemoji sprite-1f612" data-textvalue="%f0%9f%98%92" src="assets/blank.gif">" 

now, image, can 2 workable values:

the utf-8 hex value

f09f9892 

and unicode codepoint (i may referring wrong, don't know encoding).

u+1f612 

now, want take either of these values (whichever works better), , write csv file character itself. that, when viewing csv file in text editor or have you, appear as

enter image description here

though have no idea start this. maybe it's simple throwing syntax around character values, haven't been able google, because i'm not familiar enough encoding know google.

i suggest preprocessing data grab webpage instead of extracting string afterwards.

you can use decodeuricomponent() decode percent-encoded string:

decodeuricomponent('%f0%9f%98%92') 

combine jquery access data-textvalue-attribute:

decodeuricomponent($(element).data('textvalue')) 

i created simple example on jsfiddle. reason emoji doesn't render correctly in result screen in browser, font issue. when looking @ result using dom inspector (or copying text different application), result shown smiley.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -