class StringUtils {

    public static String removeFirstAndLastOccurrence(String input, String str) {
        if (input == null) {
            return null;
        }

        input = input.trim();
        if (input.isEmpty()) {
            return "";
        }

        int start = 0;
        int stop = input.length();

        if (input.startsWith(str)) {
            start = 1;
        }

        if (input.endsWith(str)) {
            stop = input.length() - 1;
        }

        input = input.substring(start, stop);

        return input;
    }

}