...
|
...
|
@@ -4,14 +4,14 @@ |
|
|
* @Last Modified by: Targaryen
|
|
|
* @Last Modified time: 2017-05-22 16:53:18
|
|
|
*/
|
|
|
let stringHandle = {
|
|
|
var stringHandle = {
|
|
|
|
|
|
/**
|
|
|
* 汉字相当于两个字符的字符串长度计算
|
|
|
* @param {*} str
|
|
|
*/
|
|
|
chinese2(str) {
|
|
|
let total = 0,
|
|
|
var total = 0,
|
|
|
charCode,
|
|
|
i,
|
|
|
len;
|
...
|
...
|
@@ -33,15 +33,15 @@ let stringHandle = { |
|
|
* @param {*} n
|
|
|
*/
|
|
|
sub_chinese2(str, n) {
|
|
|
let r = /[\u4E00-\u9FA5]/g;
|
|
|
var r = /[\u4E00-\u9FA5]/g;
|
|
|
var m = Math.floor(n / 2);
|
|
|
var i;
|
|
|
|
|
|
if (str.replace(r, 'mm').length <= n) {
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
let m = Math.floor(n / 2);
|
|
|
|
|
|
for (let i = m; i < str.length; i++) {
|
|
|
for (i = m; i < str.length; i++) {
|
|
|
if (str.substr(0, i).replace(r, 'mm').length >= n) {
|
|
|
return str.substr(0, i);
|
|
|
}
|
...
|
...
|
|