Java代码
public static String getPicSuffix(String img_path){
if (img_path == null || img_path.indexOf(".") == -1){
return ""; //如果图片地址为null或者地址中没有"."就返回""
}
return img_path.substring(img_path.lastIndexOf(".") + 1).
trim().toLowerCase();
}
//img_path.lastIndexOf(".")返回最后一次出现的.在此字符串中的索引。
//img_path.substring(img_path.lastIndexOf(".") + 1)返回一个新的字符串
//trim()清空空格
//toLowerCase()转化成小写
一个简单的Java(string)截取图片的后缀程序
最新推荐文章于 2023-05-12 19:53:16 发布