注册 登录
编程论坛 ASP技术论坛

来看看如何控制字数的显示

zhongx 发布于 2007-09-21 19:48, 1614 次点击
不论某一字段内有多少字数,都只显示控制在三百字数,后面是省略号.
如何如何如何......
11 回复
#2
madpbpl2007-09-21 19:58

用left 或mid应该都可以的
str="你的内容"
left(str,300)
if len(str)>300 then
response.write "..."
end if
大概就是这样,楼主是这个意思吗?

#3
zhongx2007-09-21 20:05
谢谢 madpbpl !
#4
zhongx2007-09-21 20:11
如果是读取数据库内的A字段的内容呢?
#5
madpbpl2007-09-22 16:27

一样的写法
left(rs("A"),300)


Left 函数
返回指定数目的从字符串的左边算起的字符。
Left(string, length)
下面的示例利用Left 函数返回MyString 的左边三个字母:
Dim MyString, LeftString
MyString = "VBSCript"
LeftString = Left(MyString, 3) 'LeftString 包含 "VBS"。


Mid 函数
从字符串中返回指定数目的字符。
Mid(string, start[, length])
本例使用 Mid 函数从字符串返回指定数量的字符。
Dim MyString, FirstWord, LastWord, MidWords As String
MyString = "Mid Function Demo" ' Creates text string.
FirstWord = Mid(MyString, 1, 3) ' Returns "Mid".
LastWord = Mid(MyString, 14, 4) ' Returns "Demo".
MidWords = Mid(MyString, 5) ' Returns "Function Demo".



#6
zsl55662007-09-22 16:33
学习……
#7
zhongx2007-09-22 17:15
解释得非常清楚,严重谢谢!
#8
zhongx2007-09-22 18:11
str="你的内容"
left(str,300)
if len(str)>300 then
response.write "..."
end if
--------------------------------

Microsoft VBScript 编译器错误 '800a0414'

调用子程序时不能使用括号

\w\index\index.asp, line 47

#9
multiple19022007-09-22 18:17
left是函数。str是传值。
#10
madpbpl2007-09-22 18:18

给你举个例子,上面只是打的比方
<%
str="asdsadsaddddddddddddddddddddddddddddddddda"
response.write left(str,10)
if len(str)>10 then
response.write "..."
end if
%>

#11
multiple19022007-09-22 18:26
同楼上。

比如你问“1与2的和怎么计算啊?”

别人可能会回答你“1+2”

那你程序里就不能只写“1+2”

要写 "response.write 1+2"
#12
zhongx2007-09-22 18:44
以下是引用madpbpl在2007-9-22 18:18:16的发言:

给你举个例子,上面只是打的比方
<%
str="asdsadsaddddddddddddddddddddddddddddddddda"
response.write left(str,10)
if len(str)>10 then
response.write "..."
end if
%>

这时会出现,如果有空格键 &nbsp; 行头时,就会只显示:&nbs... 不显示文字.

1