Java String Abbreviate abbrev(String result, int maxLength, String separator)

Here you can find the source of abbrev(String result, int maxLength, String separator)

Description

Make sure a string stays within a certain length, by cutting a bit from the middle.

License

Open Source License

Declaration

public static String abbrev(String result, int maxLength, String separator) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  w  w  w  . ja v  a  2s . c o  m*/
     * Make sure a string stays within a certain length, by cutting a bit from the middle.
     */
    public static String abbrev(String result, int maxLength, String separator) {
        int mid = maxLength / 2;
        if (result.length() > maxLength)
            result = result.substring(0, mid - 1) + separator + result.substring(result.length() - mid);
        return result;
    }
}

Related

  1. abbr(String str, int length)
  2. abbrev(String longString, int size)
  3. abbreviate(final String str)
  4. abbreviate(final String str, final int maxWidth)
  5. abbreviate(final String str, int lower, int upper, final String appendToEnd)
  6. abbreviate(final String value, final int maxLength)