Created
October 19, 2010 15:09
-
-
Save think49/634347 to your computer and use it in GitHub Desktop.
getStringByte.js : 文字列のバイト数を求める
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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