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

ASP
用asp执行DTC
利用ADODB.Stream使用浏览器下载服务器文件
应用数据库的唯一性约束并在asp中捕捉数据库的错误
用ASP编程控制在IIS建立Web站点
asp实现k线图(在线)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(7)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(6)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(5)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(4)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(3)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(2)
在ASP中用EasyMailObject组件处理Exchange邮件源代码(1)
用文本+ASP打造新闻发布系统。几点补充
用文本+ASP打造新闻发布系统(五)新闻修改
用文本+ASP打造新闻发布系统(四)新闻删除
用文本+ASP打造新闻发布系统(三)新闻列表显示
用文本+ASP打造新闻发布系统(二)新闻添加
ASP作的剪包锤游戏
ASP注册表项目修改
构建稳定的服务器端组件的七个步骤

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 141 ::
收藏到网摘: 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