我有一个字符串
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.
split[1]
将包含结果。 - DeepakString 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);
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";