Java String Truncate truncate(String s, int begin, int end)

Here you can find the source of truncate(String s, int begin, int end)

Description

truncate

License

Apache License

Declaration

public static String truncate(String s, int begin, int end) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String truncate(String s, int begin, int end) {
        if (isNullOrNone(s)) {
            return "";
        }// w w w.  j  av  a2 s.  c o m

        if (begin < 0) {
            return "";
        }

        if (begin >= end) {
            return "";
        }

        s = s.trim();
        if (begin >= s.length()) {
            return "";
        }

        if (end >= s.length()) {
            return s;
        } else {
            return s.substring(begin, end);
        }
    }

    public static boolean isNullOrNone(String s) {
        if (s == null || "".equals(s.trim())) {
            return true;
        }

        return false;
    }

    public static boolean isNullOrNone(Object obj) {
        if (obj == null) {
            return true;
        }
        if (obj instanceof String) {
            return isNullOrNone((String) obj);
        }
        return false;
    }

    public static boolean isNullOrNone(String[] ss) {
        if (ss == null || ss.length == 0) {
            return true;
        }

        for (int i = 0; i < ss.length; i++) {
            if (ss[i] == null || "".equals(ss[i].trim())) {
                return true;
            }
        }

        return false;
    }
}

Related

  1. truncate(String original, int number)
  2. truncate(String original, String ellipsis, int maxLength)
  3. truncate(String originalString, int size)
  4. truncate(String s)
  5. truncate(String s)
  6. truncate(String s, int i)
  7. truncate(String s, int length)
  8. truncate(String s, int length)
  9. truncate(String s, int length, boolean indicator)