Reputation: 13
I have a string variable in Java with the value below:
String str = "web > data > list > new_list.html";
I want my final string like so:
String str = "new_list.html";
I have tried like this:
final Pattern pattern = Pattern.compile("[\\>.]");
final String[] result = pattern.split(str);
But it is returning data > list > new_list.html
How can i get exact substring new_list.html
?
Upvotes: 0
Views: 50
Reputation: 914
Try this:
String str = "web > data > list > new_list.html";
str = str.substring(20);
Upvotes: 0
Reputation: 1430
String s = "web > data > list > new_list.html";
String newList = s.substring(s.lastIndexOf("> ") + 2);
Upvotes: 1