Skip to content

Instantly share code, notes, and snippets.

@horatio-sans-serif
Created April 19, 2010 00:08
Show Gist options
  • Save horatio-sans-serif/370636 to your computer and use it in GitHub Desktop.
Save horatio-sans-serif/370636 to your computer and use it in GitHub Desktop.
~ ⚡ node /tmp/readself.js
length=214
// start of file readself.js
sys=require("sys");
fs=require("fs");
contents=fs.readFileSync(__filename, encoding="utf8"); // ö日本語
sys.puts("length="+contents.length);
sys.puts(contents);
// end of file readself.js
~ ⚡ wc -c /tmp/readself.js
221 /tmp/readself.js
@horatio-sans-serif
Copy link
Author

sure "length" is # characters not bytes but help me figure out what's up

@inimino
Copy link

inimino commented Apr 19, 2010

"ö日本語" is four characters, and in UTF-8 "ö" is two bytes and the Han characters are each 3 bytes, so you have 7 bytes more than characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment