java字符串截取--截取倒数第三个指定字符之后的字符串

截取倒数第三个"/"之后的字符串

public static String getThirdLocation(String url){
		//index为最后的“/”字符所在的位置
        int index=url.lastIndexOf(File.separator);
        //从最后的“/”字符的前一个位置向前找“/”的位置为此index
        index=url.lastIndexOf(File.separator,index-1);
        //从倒数第二的“/”字符的前一个位置向前找“/”的位置为此index
        index=url.lastIndexOf(File.separator,index-1);
        //得到倒数第三个“/”之后的字符串
        String location=url.substring(index+1);
        return location;
    }

运行结果:
在这里插入图片描述


版权声明:本文为henry000513原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。