Hari
Hari

Reputation: 13

How to get an exact string between two characters in java

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

Answers (2)

Dumidu Udayanga
Dumidu Udayanga

Reputation: 914

Try this:

String str = "web > data > list > new_list.html";
str = str.substring(20);

Upvotes: 0

PatrickChen
PatrickChen

Reputation: 1430

String s =  "web > data > list > new_list.html";

String newList = s.substring(s.lastIndexOf("> ") + 2);

Upvotes: 1

Related Questions