<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>JavaScript 测试</title>
<script type="text/javascript">
//取得字符串的字节长度
function strLen(str){
var i,len;
len = 0;
for(i=0;i<str.length;i++){
if(str.charCodeAt(i)>255){
len+=2;
}else{
len++;
}
}
return len;
}
//验证
var str1 = "The American economic system is, organized around a basically private-enterprise, market- oriented economy in which consumers largely determine what shall be produced by spending their money in the marketplace for those goods and services that they want most."
document.write(strLen(str1));
</script>
</head>
<body>
</body>
</html>
取得字符串的字节长度
最新推荐文章于 2023-09-13 15:47:45 发布