Java String Abbreviate abbreviate(String s, int length)

Here you can find the source of abbreviate(String s, int length)

Description

abbreviate

License

Open Source License

Declaration

public static String abbreviate(String s, int length) 

Method Source Code

//package com.java2s;

public class Main {
    public static String abbreviate(String s, int length) {
        if (s == null)
            return null;
        if (s.length() <= length)
            return s;
        s = s.substring(0, length - 5);//from w  w  w  . j av  a2  s .c o  m
        if (s.endsWith(" ")) {
            s += "...";
        } else {
            s += " ...";
        }
        return s;
    }
}

Related

  1. abbreviate(String fileName, int maxLen)
  2. abbreviate(String input, int length)
  3. abbreviate(String longName)
  4. abbreviate(String longStr, int maxLength)
  5. abbreviate(String name)
  6. abbreviate(String s, int max)
  7. abbreviate(String s, int maxLength)
  8. abbreviate(String src, int maxlen, String replacement)
  9. abbreviate(String str)