/** * 获取字符串字符长度 * * @category Utils * @param string : 传入的字符串 * @returns : 字符串的字符长度 */ export const getStrLen = (string: string) => { if (string == null) return 0; let str = string; if (typeof string != 'string') { str += ''; } const len = str.length; const chineseLen = str.match(/[\u4e00-\u9fa5]/g)?.length || 0; const lowerLen = str.match(/[a-z]/g)?.length || 0; const capLen = str.match(/[A-Z]/g)?.length || 0; const numLen = str.match(/[0-9]/g)?.length || 0; const unitLen = len - chineseLen - lowerLen - capLen - numLen; return ( chineseLen * 13.2 + unitLen * 8 + lowerLen * 6.6 + capLen * 8.8 + numLen * 8.5 + 6 ); };