@NonNull
    public static String getTextBeforeIndexUntil(final String text, final int idx, final String startToken, final int maxLength) {
        if (StringUtils.isEmpty(text) || idx <= 0) {
            return "";
        }
        String before = text.substring(0, Math.min(idx, text.length()));

        if (StringUtils.isNotEmpty(startToken)) {
            final int tokenIdx = before.lastIndexOf(startToken);
            if (tokenIdx >= 0) {
                before = before.substring(tokenIdx + startToken.length());
            }
        }
        return (maxLength >= 0 && before.length() > maxLength) ? before.substring(before.length() - maxLength) : before;
    }
Returns substring of text before (and excluding) given 'idx' until one of given conditions is met

@param text       text to work on
@param idx        idx to start checking
@param startToken if not null, return text until (and excluding) this token is found
@param maxLength  if >=0, text is truncated to given max length
@return found text or empty string. Never null.
main/src/main/java/cgeo/geocaching/utils/TextUtils.java