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,
                "..."));
    }
}

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

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

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-11-11
  • 2021-11-21
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2022-12-23
  • 2021-11-13
  • 2022-01-28
  • 2021-12-05
  • 2022-12-23
  • 2022-02-02
相关资源
相似解决方案