You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
572 B
22 lines
572 B
// 处理超出字后面...
|
|
export function doStr(str, n) {
|
|
let totalCount = 0;
|
|
let txt = "";
|
|
if (str) {
|
|
for (var i = 0; i < str.length; i++) {
|
|
let c = str.charCodeAt(i);
|
|
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
|
|
totalCount++;
|
|
} else {
|
|
totalCount += 2;
|
|
}
|
|
if (totalCount <= n) {
|
|
txt += str[i];
|
|
} else {
|
|
txt += '...';
|
|
return txt
|
|
}
|
|
}
|
|
}
|
|
return txt;
|
|
} |