如何在 java 中获取两个字符之间的精确字符串
How to get an exact string between two characters in java
我在 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);
我在 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);