ASP supports the function code of Len (), left () and right () in Chinese

Source: Internet
Author: User
Tags exit

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 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 If
If lens>=l Then Exit for
Next
End Function

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.

The

also has a place for 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.

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.