ASP intercepts specified English-Chinese mixed strings _ supports Chinese Characters

Source: Internet
Author: User

Note: This function is used to intercept a specified English-Chinese mixed string and keep the display length one to one. It is to extract a Chinese character as a two-byte string.
Purpose: this function is generally used to display the list of titles, which can avoid the insertion of string parameters.
Program Code Copy code The Code is as follows: '// a_strstring the string to be processed
'// A_intlen is based on the number of English characters
'// A_straddstring if a_strstring has a suffix added when it is intercepted, such as:..., it can be blank
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_objms1_mm_objre.exe cute (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
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 what is currently popular on the Internet. The regular expression is used to obtain non-ANSI characters (here the default non-ANSI characters are Chinese characters. If there is any deviation, you can modify the regular expression to achieve the goal ). NOTE 1: The length specified by the function is based on the number of English characters. That is, 10 characters are specified and the meaning is 10 English or 5 Chinese characters.
Two optimizations were made:
The first point is to directly obtain characters of the specified length, because no matter whether it is Chinese or full English, the maximum length is only the full English length. The characters exceeding the length are definitely obsolete characters.
Second, use regular expressions to search for Chinese characters in the range and traverse only the words of each Chinese character. This can minimize the number of cycles.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.