字符串截取问题,找了很多,问了很多都没得到答案!100分
在页面上控制字符串长短,用下面的函数截取,控制了汉字和字母的区别,但是还是长短不一样,字母多的会长一些,有没有达人给出解决方案,偶厚道,200分送上!!
function gotTopic(str,strlen)
if str="" or isnull(str) then
gotTopic=""
exit function
end if
dim l,t,c, i
l=len(str)
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
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
gotTopic=left(str,i)
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
end function
问题点数:100、回复次数:7Top
1 楼bluemoon0001(小天--追梦浪子)回复于 2005-06-04 14:28:30 得分 100
function gotTopic(str,strlen)
if str="" or isnull(str) then
gotTopic=""
exit function
end if
dim l,t,c, i
l=len(str)
str=replace(replace(replace(replace(str," "," "),""",chr(34)),">",">"),"<","<")
t=0
for i=1 to l
c=Asc(Mid(str,i,1)) '不用绝对值
if c<0 then '汉字的asiic码小于0
t=t+2
else
t=t+1
end if
if t>=strlen then
gotTopic=left(str,i)
exit for
else
gotTopic=str
end if
next
gotTopic=replace(replace(replace(replace(gotTopic," "," "),chr(34),"""),">",">"),"<","<")
end function
以上试一下。Top
2 楼bluemoon0001(小天--追梦浪子)回复于 2005-06-04 14:33:23 得分 0
如果你截取的字符串中是汉字中夹着单个英文字符,他是会长一点点的。Top
3 楼bluemoon0001(小天--追梦浪子)回复于 2005-06-04 14:38:16 得分 0
你不防用下列方法试试,来达到你的效果:
<style type="text/css">
.tllist
{
width:285px;
white-space:nowrap;
word-break:keep-all;
overflow:hidden;
text-overflow:ellipsis;
}
</style>
<span class="tllist">更好的提高我们大家(说中国会不会有点过更好的提高我们大家(说中国会不会有点过更好的提高我们大家(说中国会不会有点过更好的提高我们大家(说中国会不会有点过更好的提高我们大家(说中国会不会有点过</span>
这段代码摘自于贴子:http://community.csdn.net/Expert/topic/4055/4055798.xml?temp=.6932032
作者: jzywh(江(大|中|小)鱼) ( )Top
4 楼aassdd(梦幻生)回复于 2005-06-04 14:46:22 得分 0
你应该替换完后再:l=len(str)Top
5 楼SList(雨叶秋寒)回复于 2005-06-04 15:14:03 得分 0
小天 ,谢谢 , 接分,我再开贴给你Top
6 楼bluemoon0001(小天--追梦浪子)回复于 2005-06-04 15:18:33 得分 0
呵呵,不用客气了。Top
7 楼bluemoon0001(小天--追梦浪子)回复于 2005-06-04 15:20:43 得分 0
不用再开贴谢我了,你留着分自己用吧,我不需要那么多分,我现在到asp.net中去混了。Top




