yangyin
2024-12-13 8526b974cfe1b270902d5c284faef3bc2ac6d63a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
interface String {
    gblen(): number;
}
 
/**
 * 获取中英文长度,中文2,英文1
 */
String.prototype.gblen =function () {
    let len = 0;
    for (let i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) > 127 || this.charCodeAt(i) == 94) {
            len += 2;
        } else {
            len++;
        }
    }
    return len;
};