The left () function is VBScript, and VBScript considers 1 characters as 1 characters, so left () does not get the correct character length ...

Source: Internet
Author: User
Tags exit
vbscript| Function | The left () function of the Chinese character is VBScript, and VBScript considers 1 characters as 1 characters, so the left () does not get the correct character length.

I wrote the following 3 functions to replace Len (), left () and right () in the hope of solving your problem.

'--------------------------------------------------------
' Name:lenx
' Argument:ustr
' Return:
' Description: Returns the length of the string, 1 Chinese characters length is 2
'--------------------------------------------------------

Function Lenx (ByVal uStr)
Dim thelen,x,testustr
TheLen = 0

For x = 1 to Len (USTR)
Testustr = Mid (ustr,x,1)
If ASC (TESTUSTR) < 0 Then
TheLen = TheLen + 2
Else
TheLen = TheLen + 1
End If
Next
Lenx = TheLen
End Function

'--------------------------------------------------------
' Name:leftx
' Argument:ustr strings to be processed
' The length of the Ulen to intercept
' Return:
' Description: Returns a string of the specified length, 1 Chinese characters length 2
'--------------------------------------------------------

Function Leftx (ByVal ustr,byval Ulen)
Dim i,j,uteststr,thestr

LEFTX = ""
j = 0

For i = 1 to Len (USTR)
uteststr= Mid (ustr,i,1)
Thestr = thestr & Uteststr
If ASC (UTESTSTR) < 0 Then
j = j + 2
Else
j = j + 1
End If
If J >= Ulen then exit for
Next
LEFTX = Thestr
End Function

'--------------------------------------------------------
' Name:rightx
' Argument:ustr strings to be processed
' The length of the Ulen to intercept
' Return:
' Description: Returns a string of the specified length, 1 Chinese characters length 2
'--------------------------------------------------------

Function Rightx (ByVal ustr,byval Ulen)
Dim i,j,uteststr

RIGHTX = ""
j = 0

For i = Len (uStr) to 1 step-1
Uteststr = Mid (ustr,i,1)
RIGHTX = rightx & Uteststr
If ASC (UTESTSTR) < 0 Then
j = j + 2
Else
j = j + 1
End If
If J >= Ulen then exit for
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.