博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取字符串字节长度跟截取字符串字节长度
阅读量:4555 次
发布时间:2019-06-08

本文共 670 字,大约阅读时间需要 2 分钟。

//获取字符串的字节长度 function getStringByteLength(str){
var realLength = 0; for (var i = 0; i < str.length; i++) {
charCode = str.charCodeAt(i); if (charCode >= 0 && charCode <= 128) realLength += 1; else realLength += 2; } return realLength; } //按字节截取字符串长度 function cutOutStringByteLength(str,long) {
var seeString = []; var countByteLength = 0; for(var i=0;i
= 0 && charCode <= 128){
countByteLength += 1; }else{
countByteLength += 2; } if (countByteLength <= long){
seeString.push(str[i]); } } return seeString.join(""); }

转载于:https://www.cnblogs.com/saifei/p/9018139.html

你可能感兴趣的文章
grep,awk和sed
查看>>
.NET Core WebAPI IIS 部署问题
查看>>
SystemTap 静态探针安装包
查看>>
数据模型
查看>>
[LeetCode&Python] Problem 371. Sum of Two Integers
查看>>
HDU-4288 Coder 线段树
查看>>
HDU-1878 欧拉回路 判定是否存在欧拉回路
查看>>
大道至简读后感
查看>>
[New Portal]Windows Azure Virtual Machine (22) 使用Azure PowerShell,设置Virtual Machine Endpoint...
查看>>
hdu 1404
查看>>
ACM/ICPC 之 欧拉回路两道(POJ1300-POJ1386)
查看>>
避免死锁的银行家算法
查看>>
resultMap自定义某个javaBean的封装规则代码
查看>>
oracle tkprof 工具详解
查看>>
[Django实战] 第3篇 - 用户认证(初始配置)
查看>>
简单逆向分析修改软件标题
查看>>
20180607jquery实现切换变色
查看>>
框架大集合
查看>>
Centos7单网卡带VLAN多IP配置
查看>>
element-ui radio 再次点击取消选中
查看>>