Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Created April 26, 2013 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chockenberry/5469201 to your computer and use it in GitHub Desktop.
Save chockenberry/5469201 to your computer and use it in GitHub Desktop.
Unicode trim 2
> var buf_ucs2 = new Buffer([0x35,0xD8,0x9c,0xDC])
undefined
> buf_ucs2.toString('ucs2')
'𝒜'
> var str = buf_ucs2.toString('ucs2')
undefined
> str
'𝒜'
> var buf_utf8 = new Buffer(str, 'utf8')
undefined
> buf_utf8.toString('utf8')
'𝒜'
> var result = buf_ucs2.toString('ucs2')
undefined
> result
'𝒜'
> var result = buf_ucs2.toString('utf8')
undefined
> result
'5؜�'
> result.length
3
> result.charCodeAt(0).toString(16)
'35'
> result.charCodeAt(1).toString(16)
'61c'
> result.charCodeAt(2).toString(16)
'fffd'
> var result = buf_utf8.toString('ucs2')
undefined
> result
'鷰鲒'
> var result = buf_utf8.toString('utf8')
undefined
> result
'𝒜'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment