![](/img/trans.png)
[英]How can i replace particular word from a string with another expression(string) and the another expression has to get some part of particular word
[英]how to get some particular word from String in JAVA Android?
我有一个字符串
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
从这个字符串我只需要一个字--PravinSB。
我怎么能在JAVA中这样做
尝试这个
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
String[] split = path.split("/");
String name = split[1]; //name is your result.
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
String[] split = path.split("/");
String name = split[1]; //name is your result.
检查以下链接
尝试这个:
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
String[] split = path.split("/");
String name = split[1];
也尝试这个:
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
String name=path.substring(1,status.length()-39);
如果您确定PravinSB将成为第一项,那么以上所有答案都是正确的。 但是如果连一个项目都加上说/a/PravinSB/servlet/com.gjgj.rmf.controllers.Hello那么它将是错误的解决方案。
String path = "/PravinSB/servlet/com.gjgj.rmf.controllers.Hello";
int indexOfString = path.indexOf("PravinSB");
int indexOfNextSlash = path.indexOf("/", indexOfString);
String name=path.substring(indexOfString,indexOfNextSlash);
这将是有效的,即使字符串是
String path = "/a/PravinSB/servlet/com.gjgj.rmf.controllers.Hello";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.