一段字符截取的函数,不知道两个的区别

slayerbb 2004-06-08 02:34:07
比较一下函数?
不明白为什么硬要使用asc进行转换。。。。。。

------===========-------the first function---=============---------
function procstr(strtxt,slen)
nlen = 0
outstr=""
for psi=1 to len(strtxt)
asci=asc(mid(strtxt,psi,1))
if asci>0 and asci<=255 then
nlen = nlen + 1
if nlen<=slen then outstr=outstr+mid(strtxt,psi,1)
else
nlen = nlen + 2
if nlen<=slen then outstr=outstr+mid(strtxt,psi,1)
end if
next
procstr=outstr
if nlen>slen then procstr=procstr&"..."
End function
------===========-------the second function---=============---------
function procstr(strtxt,slen)
dim outstr
if len(strtxt)>slen then
outstr=left(strtxt,slen)
outstr=outstr&"..."
else
outstr=strtxt
end if
procstr=outstr
End function

请知道的帮忙分析一下
20分感谢:)

...全文
126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
slayerbb 2004-06-08
  • 打赏
  • 举报
回复
ok
done
closed
thanks
amadou
ama ?

hoho
amadou 2004-06-08
  • 打赏
  • 举报
回复
asci 0---255 是判断中英文的条件么?
忘记了。。。

ASCII的256个半角字符
skyboy0720 2004-06-08
  • 打赏
  • 举报
回复
<%
'字符串的真实长度
Function GetStrLength(Str)
dim objRegExp
Set objRegExp=new RegExp
objRegExp.IgnoreCase =true
objRegExp.Global=True
objRegExp.Pattern="[^\x00-\xff]"
Str=objRegExp.Replace(Str,"**")
GetStrLength = len(Str)
End Function

Response.Write(GetStrLength("中e"))
%>
slayerbb 2004-06-08
  • 打赏
  • 举报
回复
asci 0---255 是判断中英文的条件么?
忘记了。。。
amadou 2004-06-08
  • 打赏
  • 举报
回复
第一个函数把英文字符算1单位的长度,而中文字符算2单位的长度,第二个函数则不论中文英文都算1单位的长度

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧