public static void main(String[] args) throws IOException {
String str = "20170913-HRBP主管-张小莉.doc";
String nameString=getFullName(str);
System.out.println(nameString);
}
public static String getFullName(String str) {
String name;
if (str == null || str.length() < 1) {
System.out.println("空串");
return "";
}
int lastIndex = str.lastIndexOf("-");
int docIndex = str.lastIndexOf(".doc");
if (lastIndex == -1 || docIndex == -1) {
System.out.println("数据不合法");
return "";
}
System.out.println("-符号最后的index:" + lastIndex);
System.out.println(".doc 最后的idex:" + docIndex);
//载取,beginIndex包含当前位置需要 lastIndex+1
name = str.substring(lastIndex + 1, docIndex);
System.out.println("成功获取到姓名:"+name);
return name;
}
字符串截取,根据职位名称后面的-姓名. 截取姓名
最新推荐文章于 2024-08-12 01:30:59 发布