Support for Chinese Len, left, right function

Source: Internet
Author: User

'------------------------------------------------------------
' Description: Let Len,left,right function recognize Chinese
' The Chinese is recognized as two characters and the ASCII code is a
' Use this function instead of the Len,left,right function
' Example: Lenx ("Chinese ren") = "7"
' Leftx ("Ren of China", 4) = "China"
' Rightx ("Ren of China", 5) = "Guo Ren"
Parameters
' Sstring string
' Llength length
' Return: string length, String, string
' Finishing: Kimsoft (jinqinghua@gmail.com)
' Time: 2005-05-24
' Modified: 2005-07-07
'------------------------------------------------------------
Public Function Lenx (ByVal sstring)
Lenx = 0

Dim Lngstringlen
Dim strcharstring
Dim I

Lngstringlen = Len (sstring)
strcharstring = ""

For i = 1 to Lngstringlen
strcharstring = Mid (sstring, I, 1)
If ASC (strcharstring) > 0 Then
Lenx = Lenx + 1
Else
Lenx = Lenx + 2
End If
Next
End Function

Public Function leftx (ByVal sstring, ByVal llength)

LEFTX = ""

If sstring = "" Or llength < 1 then Exit Function

Dim Lngstringlength
Dim strcharstring
Dim Lngcounter
Dim I

Lngstringlength = Len (sstring)

For i = 1 to Lngstringlength
strcharstring = Mid (sstring, I, 1)
LEFTX = LEFTX & strcharstring
If ASC (strcharstring) > 0 Then
Lngcounter = Lngcounter + 1
Else
Lngcounter = Lngcounter + 2
End If
If lngcounter >= Llength then Exit for
Next

End Function

Public Function rightx (ByVal sstring, ByVal llength)

RIGHTX = ""

If sstring = "" Or llength < 1 then Exit Function

Dim Lngstringlength
Dim strcharstring
Dim Lngcounter
Dim I

Lngstringlength = Len (sstring)

For i = Lngstringlength to 1 Step-1
strcharstring = Mid (sstring, I, 1)
RIGHTX = strcharstring & rightx
If ASC (strcharstring) > 0 Then
Lngcounter = Lngcounter + 1
Else
Lngcounter = Lngcounter + 2
End If
If lngcounter >= Llength 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.