简体   繁体   English

如何在 java 中的两个字符之间获取精确的字符串

[英]How to get an exact string between two characters in java

I have a string variable in Java with the value below:我在 Java 中有一个字符串变量,其值如下:

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但它正在返回data > list > new_list.html

How can i get exact substring new_list.html ?我怎样才能得到准确的 substring new_list.html

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

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

Try this:尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM