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


    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时

    设置为零时

  • 相关阅读:
    DOM getElementById
    百度之星2014
    游艇租借
    2014年acm亚洲区域赛·鞍山站
    UVALive 4255 Guess
    UVA 10054 The Necklace
    UVA 10047 The Monocycle
    UVA 11624 Fire!
    第九届黑龙江省赛
    剑指offer系列31-----二叉树的下一个节点
  • 原文地址:https://www.cnblogs.com/tufujie/p/5055308.html
Copyright © 2020-2023  润新知