Skip to content

Instantly share code, notes, and snippets.

@cssoul
Last active March 4, 2022 03:33
Show Gist options
  • Save cssoul/5479602 to your computer and use it in GitHub Desktop.
Save cssoul/5479602 to your computer and use it in GitHub Desktop.
获取字符串的字节长度
new function(s)
{
if(!arguments.length||!s) return null;
if(""==s) return 0;
var l=0;
for(var i=0;i<s.length;i++)
{
if(s.charCodeAt(i)>255)
{
l+=2;
}else{
l++;
}
}
console.log(l);
}("hello,world!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment