I have one String
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
from this String I need only word - PravinSB.
How can I do this in JAVA
I have one String
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
from this String I need only word - PravinSB.
How can I do this in JAVA
Try this
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.
check below link
Try this:
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
String[] split = path.split("/");
String name = split[1];
also try this:
String path = /PravinSB/servlet/com.gjgj.rmf.controllers.Hello
String name=path.substring(1,status.length()-39);
If you are sure that PravinSB is going to be first item then all above answer is true. But in case even a single item is added say /a/PravinSB/servlet/com.gjgj.rmf.controllers.Hello then its going to be wrong solution.
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);
this will work even if the string is
String path = "/a/PravinSB/servlet/com.gjgj.rmf.controllers.Hello";