ASP support Chinese Len (), left (), right () function code _ Application Tips

Source: Internet
Author: User
For example, a Chinese character will only be counted as a byte, in typesetting, if all is Chinese characters, say, anyway, no difference, but if the string has been manipulated by Chinese characters and English letters, it is inconvenient, the following three functions can replace the ASP's own related functions.

There are also areas of attention, if used in a loop, because the invariant "I" is also a variable that is often used for loops, the value of "I" will change when the following function is executed, and if the same variable is used in the call to his loop, an unknown result is generated, please replace it with another variable name.

The following usage is the same as Len (), left (), and Right ().

Program code
Copy Code code 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=strlengt H+2
End If
Next
End Function

function Strleft (str,l)
Temp_str=len (STR)
for I=1 T o temp_str
test_str= (Mid str,i,1)
Strleft=strleft&test_str
If Asc (test_str) >0 Then
Lens=le Ns+1
Else
lens=lens+2
End If
if Lens>=l Then Exit for
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 I F
If lens>=l Then Exit for
Next
End Function
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.