A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李进 黑马帝   /  2011-8-4 12:01  /  2099 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

用。。。代替

评分

参与人数 1技术分 +1 收起 理由
老罗 + 1 截取一段,然后append

查看全部评分

1 个回复

倒序浏览
黑马网友  发表于 2011-8-5 12:28:24
沙发

问题自个解决

[code]public  static String truncate(String source,int len,String delim){
                if(source==null)
                return null;
                int start ,stop,byteLen;
                int alen=source.getBytes().length;
                if(len>0){
                if(alen<=len)
                return source;
                start=stop=byteLen=0;
                while(byteLen<=len){
                if(source.substring(stop,stop+1).getBytes().length==1){
                byteLen+=1;
                }else{
                byteLen+=2;
                }
                stop++;
                }
                StringBuffer sb=new StringBuffer(source.substring(start,stop-1));
                if(alen>len)sb.append(delim);
                return sb.toString();
                }
                return source;
                }[/code]然后进行调用就可以
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马