您的位置:首页 > 其它

内容太长,显示其中的一部分

2015-12-17 21:09 225 查看
package com.tfj.demo;

/**
* @date 2015年12月17日 下午8:57:08
*/
public class Test2 {
public static String StringTruncat(String oldStr, int maxLength, String endWith) {
// 判断原字符串是否为空
if (oldStr.equals(""))
return oldStr + endWith;
// 返回字符串的长度必须大于1
if (maxLength < 1)
System.out.println("请将返回的字符串长度设置成大于0");
// 判断原字符串是否大于最大长度
if (oldStr.length() > maxLength) {
// 截取原字符串
String strTmp = oldStr.substring(0, maxLength);
// 判断后缀是否为空
if (endWith.equals(""))
return strTmp + "...";
else
return strTmp + endWith;
}
return oldStr;
}

public static void main(String[] args) {

System.out.println(Test2.StringTruncat("这个链接时某某某在某某某网站分享的某某某文件,有兴趣的可以自行下载查看,不喜勿喷,谢谢", 16,
"..."));
}
}






maxLength设置为0时



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: