java中如何截取字符串中的指定一部分?

比如 F:\workspace\ssh_photo\WebContent\uploadFile\1444783552338pic.jpg 想截取后面的文件名。

第1个回答  推荐于2019-08-04

具体方法如下:   

String useName=

F:\workspace\ssh_photo\WebContent\uploadFile\1444783552338pic.jpg ;

int begin=useName.indexOf(“.”);

int last=useName.length();

System.out.println(useName.substring(begin,last)); 

  方法介绍:  

public String substring(int beginIndex, int endIndex);

第一个int为开始的索引,对应String数字中的开始位置。第二个是截止的索引位置,对应String中的结束位置.

本回答被网友采纳
相似回答