ASP函数:支持中文的Len, Left, Right,如何让Len,Left,Right函数识别中文
对中文识别为两个字符,ASCII码为一个,可用此函数代替Len,Left,Right函数
示例:LenX("中国ren") => "7"
LeftX("中国ren",4) => "中国"
RightX("中国ren",5) => "国ren"
参数: 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