ASP中怎么限制label显示的字符长度,多的字符用....代替

 我来答
匿名用户
2013-09-05
展开全部
'''''''''''''''''''''''''''''''''''''''''''''''
'''截取字符串函数
'''''''''''''''''''''''''''''''''''''''''''''''
function cutStr(str,strlen)
If str = "" Then
cutStr = "cutStr函数异常:字符串为空"
exit function
End If
'------------来源长度检查
If strlen = "" Then
cutStr = "cutStr函数异常:长度未指定"
exit function
End If If CInt(strlen) = 0 Then
cutStr = "cutStr函数异常:长度为0"
exit function
End If
'----------检测来源字符长度
dim l,t,c,i
l = len(str)
t = 0
'----------循环截取字符
for i = 1 to l
c = Abs(Asc(Mid(str,i,1)))
'------判断是否汉字
if c > 255 then
t = t + 2
else
t = t + 1
end If
'------判断是否到达指定长度
if t >= strlen then
cutStr = left(str,i)&"..."
exit for
else
cutStr = str
end if
next
cutStr = replace(cutStr,chr(10),"")
end function 调用方法<%Response.Write(cutStr(RS("你的字符串"),20)&"")%>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-09-05
展开全部
一个截取五个字符的例子,<body>
<%
x="xxxxxxxxxxxxxxx"
%>
<label><%if len(x)>10 then
response.Write(left(x,5)&"...")
else
response.Write(x)
end if
%></label>
</body> len("字符串")判断字符串长度left("字符串",x) 从左边起截取字符串x位(x是个数字,代表截取多少位)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式