ASP supports Chinese Len (), left (), right () function code

Source: Internet
Author: User

For example, a Chinese character can only be regarded as one byte. If it is all Chinese Characters During the typographical process, there is no difference. However, if the operated string contains Chinese characters and English letters, this is inconvenient. The following three functions can replace the relevant functions provided by ASP.

Note that, when used in a loop, the variable "I" is also commonly used in the loop. When the following function is executed, the value of "I" changes, if the same variable is used in the call cycle, unknown results will be generated. Please use another variable name.

The following uses the same as Len (), left (), right.

ProgramCode Copy codeThe Code is as follows: function strlength (STR)
Temp_str = Len (STR)
For I = 1 to temp_str
Test_str = (mid (STR, I, 1 ))
If ASC (test_str)> 0 then
Strlength = strlength + 1
Else
Strlength = strlength + 2
End if
Next
End Function

Function strleft (STR, L)
Temp_str = Len (STR)
For I = 1 to temp_str
Test_str = (mid (STR, I, 1 ))
Strleft = strleft & test_str
If ASC (test_str)> 0 then
Lens = Lens + 1
Else
Lens = Lens + 2
End if
If lens> = l then exit
Next
End Function

Function strright (STR, L)
Temp_str = Len (STR)
For I = temp_str to 1 step-1
Test_str = (mid (STR, I, 1 ))
Strright = test_str & strright
If ASC (test_str)> 0 then
Lens = Lens + 1
Else
Lens = Lens + 2
End if
If lens> = l then exit
Next
End Function

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.