Java String Abbreviate abbreviate(String text, int maxFront, int maxBack)

Here you can find the source of abbreviate(String text, int maxFront, int maxBack)

Description

abbreviate

License

Open Source License

Declaration

public static String abbreviate(String text, int maxFront, int maxBack) 

Method Source Code

//package com.java2s;
/*//from  w  w w . jav  a 2 s. co m
(C) 2007 Stefan Reich (jazz@drjava.de)
This source file is part of Project Prophecy.
For up-to-date information, see http://www.drjava.de/prophecy
    
This source file is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
*/

public class Main {
    public static String abbreviate(String text, int maxFront, int maxBack) {
        if (text.length() > maxFront + maxBack - 3) {
            text = text.substring(0, maxFront) + "..." + text.substring(text.length() - maxBack, text.length());
        }
        return text;
    }

    /** abbreviate to default length */
    public static String abbreviate(String text) {
        return abbreviate(text, 40, 20);
    }
}

Related

  1. abbreviate(String str, int maxWidth)
  2. abbreviate(String str, int maxWidth)
  3. abbreviate(String str, int offset, int maxWidth)
  4. abbreviate(String str, int preferredLength)
  5. abbreviate(String string, int maxLength)
  6. abbreviate(String text, Number maxNbrChars)
  7. abbreviate(String time)
  8. abbreviated(final String str, final int maxLength)
  9. abbreviateDotSeparatedString(String string, int targetLength)