String 常用API

public static void main(String[] args) {
        /**
         * String 常用API
         * 字符串
         *   1>截取
         *   2>替换
         *
         */
        String fileSuffix = ".jpg";
        int i = fileSuffix.indexOf(".");

        //截取.之后的内容,包含. indexs+0
        String newStr = fileSuffix.substring(i+ 0);

        //截取.之后的内容,不包含. indexs+1
        String newStr2 = fileSuffix.substring(i + 1);

        System.out.println("包含.   :"+newStr);
        System.out.println("不包含.  :"+newStr2);


        String separator = "webapps\\com\\gblfy";
        System.out.println("将.替换为@   :"+fileSuffix.replace(".","@"));
        System.out.println("将双\\替换为单/ :"+separator.replace("\\","/"));
    }

你可能感兴趣的:(Java)