Skip to content

Instantly share code, notes, and snippets.

@think49
Created October 19, 2010 15:09
Show Gist options
  • Save think49/634347 to your computer and use it in GitHub Desktop.
Save think49/634347 to your computer and use it in GitHub Desktop.
getStringByte.js : 文字列のバイト数を求める
function getStringByte (str) {
return encodeURIComponent(str).replace(/%[\da-zA-Z]+/g, '.').length;
}
alert(getStringByte('テスト')); // 9
alert(getStringByte('test')); // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment