当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP技巧:让Len,Left,Right函数识别中文

ASP
Asp Object 之:End
Asp Object 之:ServerVariables
Asp Object 之:Expires
Asp Object 之:ExpiresAbsolute
Asp Object 之:Flush
Asp Object 之:Form
Asp Object 之:IsClientConnected
Asp Object 之:PICS
Asp Object 之:QueryString
Asp Object 之:Redirect
Asp Object 之:Request.Cookies
Asp Object 之:Request
Asp Object 之:Response.Cookies
Asp Object 之:Response
Asp Object 之:Status
Asp Object 之:TotalBytes
Asp Object 之:Write
用ASP.Net编写留言本
如何把ASP编写成DLL(1)
如何把ASP编写成DLL(2)

ASP技巧:让Len,Left,Right函数识别中文


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 161 ::
收藏到网摘: n/a

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