Description: This function is to intercept the specified English-Chinese mixed string, and keep the display length one to. is to intercept a Chinese character in two English languages.
Use: Generally used in the title display list, you can avoid the interception of the string parameter interpolation phenomenon.
Program code
Copy Code code as follows:
'//a_strstring the string to be processed
'//a_intlen the number of English characters
'//a_straddstring if a_strstring has the suffix that is added in the intercept character, such as: ..., can be empty
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 ' Global Search
Mm_objre.ignorecase=true ' case-insensitive
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
This is not the same as the current online popular, with a regular formula to obtain non-ANSI characters (here the default non-ANSI characters are Chinese characters, if there are deviations can modify the regular formula to achieve the purpose). First Note: The function specifies the length of the number of English characters. is specified as 10, meaning 10 English or 5 Chinese characters
Two-point optimizations are made:
1th: Directly to obtain the specified length of the characters, because whether the whole Chinese or English, the longest is the full English length, more than the character is absolute elimination characters.
2nd: Use the regular search scope of the Chinese characters, and only to traverse the word number of each Chinese character, so as to maximize the reduction of cycle times.