[英]How can I verify that my string ends with a particular data?
I have a String 我有一个弦
String s = "a/b/c/d/data/info";
I need to find is info
exist. 我需要找到
info
存在。 And info
should follow right after data
. info
应该紧随data
之后。 How can I verify that my string ends with a particular data ( info
)? 如何验证我的字符串以特定数据(
info
)结尾?
UPD UPD
I need to find and retrieve string which follows .../data/{thisString}
我需要查找并检索在
.../data/{thisString}
字符串
s.endsWith( "data/info" )
is true
. 是
true
。
EDIT: OK, so "info" is just your stand-in for any string. 编辑:好的,所以“信息”只是您的任何字符串的替身。 You could check for the "data/" with
indexOf
and then use substring
to get just the "info" part. 您可以使用
indexOf
检查“ data /”,然后使用substring
获取“ info”部分。
String s = "a/b/c/data/info";
String info = null;
if( s.indexOf( "data/" ) >= 0 ) {
info = s.substring( s.indexOf( "data/" ) + "data/".length() );
}
System.out.println( info );
You can use: 您可以使用:
String repl = "a/b/c/d/data/info".replaceFirst("^.*?data/([^/]+)$", "$1");
//=> info
Username after data/: 数据后的用户名/:
String s = "a/b/c/d/data/info";
System.out.println(s.split("data/")[1]);
outputs: 输出:
info
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.