java中 IndexOf()、lastIndexOf()、substring()的用法

public int indexof(String str)返回字符串中出现str的第一个位置

public int indexof(String str,int fromIndex)返回字符串中从fromIndex开始出现str的第一个位置

public String substring(int beginIndex)返回从beginIndex开始的字符串

public String lastIndexOf(String str)返回从str最后一次出现的位置

如:

String pexfix = fileName.substring(
fileName.lastIndexOf("."),
fileName.length());

返回字符串pexfix中以.结束的位置到整个字符串结束之间的字符串,即获取后缀名

猜你喜欢

转载自blog.csdn.net/boguesfei/article/details/81367728