[JAVA] removeFirstSlice, removeLastSlice

[JAVA] removeFirstSlice, removeLastSlice

/**
     * 문자열(text) 안에 특정 문자열(slice)이 존재할 경우 앞에서부터 1개 제거
     *
     * @param text
     * @param slice
     * @return
     */
    public static String removeFirstSlice(String text, String slice) {
        if (text == null || text.length() == 0) {
            return “”;
        }
       
        if (slice == null || slice.length() == 0) {
            return text;
        }
       
        int idxSlice = text.indexOf(slice);
        if (idxSlice > -1) {
            text = text.substring(0, idxSlice) + text.substring(idxSlice + slice.length());
        }
       
        return text;
    }
   
   
    /**
     * 문자열(text) 안에 특정 문자열(slice)이 존재할 경우 뒤에서부터 1개 제거
     *
     * @param xml
     * @param slice
     * @return
     */
    public static String removeLastSlice(String text, String slice) {
        if (text == null || text.length() == 0) {
            return “”;
        }
       
        if (slice == null || slice.length() == 0) {
            return text;
        }
       
        int idxSlice = text.lastIndexOf(slice);
        if (idxSlice > -1) {
            text = text.substring(0, idxSlice) + text.substring(idxSlice + slice.length());
        }
       
        return text;
    }