ASP functions: supports Chinese Len, left, right, how to make Len, left, right functions recognize Chinese Characters
Recognize Chinese characters as two characters with an ascii code. Use this function to replace Len, left, and right functions.
Example: lenx ("China Ren") => "7"
Leftx ("China Ren", 4) => "China"
Rightx ("China Ren", 5) => "Guo Ren"
Parameter: String Length
Return Value: String Length, String, string
Public Function lenx (byval sstring)
Dim reslult, lngstringlen, strcharstring, I
Lngstringlen = Len (sstring)
Strcharstring = ""
For I = 1 to lngstringlen
Strcharstring = mid (sstring, I, 1)
If ASC (strcharstring)> 0 then reslult = reslult + 1 else reslult = reslult + 2
Next
Lenx = reslult
End Function
Public Function strleft (byval sstring, byval llength)
If isblank (sstring) or llength <1 then exit function
Dim result, lngstringlength, strcharstring, lngcounter, I
Lngstringlength = Len (sstring)
Result = ""
For I = 1 to lngstringlength
Strcharstring = mid (sstring, I, 1)
Result = Result & strcharstring
If ASC (strcharstring)> 0 then lngcounter = lngcounter + 1 else lngcounter = lngcounter + 2
If lngcounter> = llength then exit
Next
Strleft = Result
End Function
Public Function strright (byval sstring, byval llength)
If isblank (sstring) or llength <1 then exit function
Dim result, lngstringlength, strcharstring, lngcounter, I
Lngstringlength = Len (sstring)
Result = ""
For I = lngstringlength to 1 step-1
Strcharstring = mid (sstring, I, 1)
Result = strcharstring & Result
If ASC (strcharstring)> 0 then lngcounter = lngcounter + 1 else lngcounter = lngcounter + 2
If lngcounter> = llength then exit
Next
Strright = Result
End Function