Java String Truncate truncate(String string, int n, String suffix)

Here you can find the source of truncate(String string, int n, String suffix)

Description

truncate

License

Open Source License

Declaration

public static String truncate(String string, int n, String suffix) 

Method Source Code

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

public class Main {
    public static String truncate(String string, int n, String suffix) {
        if (string.length() - suffix.length() > n) {
            return string.substring(0, n) + suffix;
        }//from   w w w . jav  a 2 s.  c  o m
        return string;
    }
}

Related

  1. truncate(String str, String prefix, String suffix)
  2. truncate(String string, final int length)
  3. truncate(String string, int length)
  4. truncate(String string, int maxLength, boolean atBeginning, String ellipse)
  5. truncate(String string, int maxSize)
  6. truncate(String strOrginal, int iByteMaxSize)
  7. truncate(String text)
  8. truncate(String text, int len)
  9. truncate(String text, int length)