CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

字符串截取问题,找了很多,问了很多都没得到答案!100分

楼主SList(雨叶秋寒)2005-06-04 14:15:23 在 Web 开发 / ASP 提问

在页面上控制字符串长短,用下面的函数截取,控制了汉字和字母的区别,但是还是长短不一样,字母多的会长一些,有没有达人给出解决方案,偶厚道,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,"&nbsp;","   "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")  
  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,"   ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")  
  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,"&nbsp;","   "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")  
  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,"   ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")  
  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

相关问题

  • 截取字符串
  • 截取字符串
  • 字符串截取
  • 字符串截取
  • 截取字符串
  • 如何截取字符串"a /b /c /d /",得到a,b,c,d
  • 如何截取字符串?
  • 字符串截取问题
  • 字符串截取问题
  • 字符串截取问题

关键词

  • 中国
  • thengottopic
  • gottopic
  • replace
  • strlen
  • chr
  • 说中国会不会
  • str
  • exit
  • 好的提高我们大家

得分解答快速导航

  • 帖主:SList
  • bluemoon0001

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo