ASP函數(shù):支持中文的Len, Left, Right,如何讓Len,Left,Right函數(shù)識別中文
對中文識別為兩個(gè)字符,ASCII碼為一個(gè),可用此函數(shù)代替Len,Left,Right函數(shù)
示例:LenX("中國ren") => "7"
LeftX("中國ren",4) => "中國"
RightX("中國ren",5) => "國ren"
參數(shù): String 字符串 Length 長度
返回:字符串長度,字符串,字符串
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