Java String Truncate truncateString(String str, int size)

Here you can find the source of truncateString(String str, int size)

Description

truncate String

License

Open Source License

Declaration

public static String truncateString(String str, int size) 

Method Source Code

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

public class Main {
    public static String truncateString(String str, int size) {
        if (size <= 0 || size > str.length()) {
            return str;
        }/*from ww w . jav  a2s  .  c o m*/

        return str.substring(0, size);

    }

    public static String substring(String str, int offset, int length) {

        if ((offset + length) > str.length()) {
            length = str.length() - offset;
        }

        return str.substring(offset, offset + length);
    }
}

Related

  1. truncateString(String source, int prefixLength, int totalLength)
  2. truncateString(String source, String suffix)
  3. truncateString(String str, int length)
  4. truncateString(String str, int length, String suffix)
  5. truncateString(String str, int maxlen)
  6. truncateString(String str, int toLen)
  7. truncateString(String string, int maxLength)
  8. truncateString(String text, int truncateAt)
  9. truncateStringAt(String source, int len)