Java String Shorten shorten(String s)

Here you can find the source of shorten(String s)

Description

shorten

License

Apache License

Declaration

public static String shorten(String s) 

Method Source Code

//package com.java2s;
/*/*from   w  ww  .  j a  v a 2 s . co  m*/
   Copyright 2014-2016 PetaByte Research Ltd.
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

public class Main {
    public static String shorten(String s) {
        if (null == s) {
            return "NULL";
        }
        if (/* s.length() > 50 || */s.indexOf("\n") > -1) {
            int lines = s.split("\n").length;
            int length = s.length();
            s = s.replaceAll("\n", "\\n");
            return String.format("%s(...)%s (len: %d, lines: %d)", s.substring(0, 10),
                    s.substring(length - 10, length), length, lines);

        } else {
            return s;
        }
    }
}

Related

  1. shorten(String line)
  2. shorten(String msg, int front, String join, int end)
  3. shorten(String name, int max)
  4. shorten(String nameForUI, int maxLen)
  5. shorten(String pkg, boolean shorten)
  6. shorten(String s)
  7. shorten(String s)
  8. shorten(String s)
  9. shorten(String s, int len)