Android String Sub String Get substringWithoutException(String text, int startIndex, int endIndex)

Here you can find the source of substringWithoutException(String text, int startIndex, int endIndex)

Description

substring Without Exception

License

Open Source License

Declaration

public static String substringWithoutException(String text,
            int startIndex, int endIndex) 

Method Source Code

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

public class Main {
    public static String substringWithoutException(String text,
            int startIndex, int endIndex) {
        if (isNullOrEmpty(text) || startIndex >= text.length()) {
            return "";
        }/*  www  . ja  v a2  s.  c  o m*/

        final StringBuilder stringBuilder = new StringBuilder();
        final int realEndIndex = endIndex >= text.length() ? text.length() - 1
                : endIndex;

        for (int i = startIndex; i <= realEndIndex; i++) {
            stringBuilder.append(text.charAt(i));
        }

        return stringBuilder.toString();
    }

    public static boolean isNullOrEmpty(String string) {
        return string == null || string.isEmpty();
    }
}

Related

  1. subStringByByte(String str, int startPos, int length)
  2. subStringByByte(String paramString, int beginIndex, int endIndex)
  3. subString(String source, String start, int offsetStart, String end, int offsetEnd)
  4. subString(String str, int length)
  5. subInStringByFlag(String str, String flag)
  6. subString(String str)
  7. replace(String s, String oldSub, String newSub)
  8. replace(String s, String[] oldSubs, String[] newSubs)
  9. substring(String str, int beginIndex)