ASP函數:支持中文的Len, Left, Right
'------------------------------------------------------------
'描述:讓Len,Left,Right函數識別中文
' 對中文識別為兩個字符,ASCII碼為一個
' 可用此函數代替Len,Left,Right函數
'示例:LenX("中國ren") => "7"
' LeftX("中國ren",4) => "中國"
' RightX("中國ren",5) => "國ren"
'參數:
' sString 字符串
' lLength 長度
'返回:字符串長度,字符串,字符串
'整理:KimSoft([email protected])
'時間:2005-05-24
'修改:2005-07-07
'------------------------------------------------------------
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 For
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 For
next
strRight = result
End Function