說明:本函數(shù)作用是截取指定英漢混合字符串,并保持顯示長度一至。就是將一個漢字當(dāng)兩英文來截取。 用途:一般會用在標(biāo)題顯示列表,可以避免截取的字符串參插不齊的現(xiàn)象。 程序代碼 復(fù)制代碼 代碼如下: '//A_strString要處理的字符串 '//A_intLen以英文字符數(shù)為準(zhǔn) '//A_strAddString如果A_strString有截取字符時添中的后綴,如:...,可以為空 function CutString(byval A_strString,byval A_intLen,byval A_strAddString) dim MM_objRe,MM_objMs,MM_objMh dim MM_strCut,MM_intLen set MM_objRe=new RegExp MM_objRe.Global=true'全局搜索 MM_objRe.IgnoreCase=true'不區(qū)分大小寫 MM_objRe.Pattern="[^/x00-/xff]"
MM_intLen=A_intLen if len(A_strString)<=A_intLen then MM_strCut=A_strString else MM_strCut=left(A_strString,MM_intLen) set MM_objMs=MM_objRe.execute(MM_strCut) if MM_objMs.count<>MM_intLen then for each MM_objMh in MM_objMs if MM_objMh.FirstIndex<MM_intLen then MM_intLen=MM_intLen-1 else exit for end if next else MM_intLen=MM_intLen/2 end if MM_strCut=left(A_strString,MM_intLen) & A_strAddString end if CutString=MM_strCut set MM_objRe=nothing end function