SOURCE

function getSubString(str,len){
    let reg = /[a-z,A-Z,0-9]/g; //匹配任意字母
    let nStr = "", l = 0, m = "...";
    if(str.length>len) {
        for (let i=0; i<str.length; i++) {
            nStr += str[i];
            l += str[i].match(reg) ? 0.5 : 1;
            if (i==str.length-1) m = "";
            if(l>=len) break;
        }
        return nStr+m;
    } else return str;
}
let s = "PPTclass智慧教育解决方案";
console.log(getSubString(s,10));
console 命令行工具 X clear

                    
>
console