我在Java中有一个字符串变量,其值如下:
String str = "web > data > list > new_list.html";
我想要这样的最终字符串:
String str = "new_list.html";
我尝试过这样:
final Pattern pattern = Pattern.compile("[\\>.]");
final String[] result = pattern.split(str);
但是它返回data > list > new_list.html
如何获得确切的子字符串new_list.html
?
String s = "web > data > list > new_list.html";
String newList = s.substring(s.lastIndexOf("> ") + 2);
尝试一下:
String str = "web > data > list > new_list.html";
str = str.substring(20);