ASP怎么也看不懂这个函数

来源:百度知道 编辑:UC知道 时间:2024/07/05 08:28:57
Function SplitWords(mys,coun)
dim ts,i,l
if isnull(mys) then exit Function
ts = 0
For i = 1 To Len(mys)
l = Mid(mys, i, 1)'从字符串中返回指定数目的字符
If Asc(l) > 0 and Asc(l) < 255 Then' Asc 返回每一个字符串首字母的 ANSI 字符代码
ts = ts + 1
End If
if i-ts/2 > coun then exit for
Next
If i-ts/2 > coun Then
ts=ts\2+coun
mys = left(mys,ts)
end if
SplitWords=mys
end Function

我以实例来给你做下解析:

<%
Function SplitWords(mys,coun)
dim ts,i,l
if isnull(mys) then exit Function
ts = 0
For i = 1 To Len(mys)
l = Mid(mys, i, 1)'从字符串中返回指定数目的字符
If Asc(l) > 0 and Asc(l) < 255 Then' Asc 返回每一个字符串首字母的 ANSI 字符代码
ts = ts + 1
End If
if i-ts/2 > coun then exit for
Next
If i-ts/2 > coun Then
ts=ts\2+coun
mys = left(mys,ts)
end if
SplitWords=mys
end Function
mys="商语软件提供网站建设和网站开发服务,提供各类程序定做,大家有需要可百度HI我。。"
mys2="www.shangyusoft.com"
mys=splitwords(mys,19)
mys2=splitwords(mys2,19)
response.write mys &"<br />"&mys2
'函数的作用是:对汉字和英文字符进行识别,自动取前N个字符,以上是对中文和英文字符取前19个的效果
'该例子显示的结果为:
'中文的前19个截取的结果为:商语软件提供网站建设和网站开发服务,提
'英文的mys2截取的前19个为: