js截取字符串
js截取字符串
function cutstr(str, len,bPoint) {
var temp;
var icount = 0;
var patrn = /[^\x00-\xff]/;
var strre = "";
var iaddcount=0;
for (var i = 0; i < str.length; i++) {
if (icount < len - 1) {
temp = str.substr(i, 1);
if (patrn.exec(temp) == null) {
icount = icount + 1;
} else {
icount = icount + 2;
}
strre += temp;
iaddcount++;
} else {
break;
}
}
if(iaddcount<str.length && bPoint)
{
strre=strre + "...";
}
return strre;
}