String xStr = "hello/master/yoda";
String remv_last = xStr.substring(0, xStr.lastIndexOf("/"))
System.out.println(remv_last);
output
hello/master
My question is; how can I get this output, thanks for helping.
master/yoda
String xStr = "hello/master/yoda";
String remv_last = xStr.substring(0, xStr.lastIndexOf("/"))
System.out.println(remv_last);
output
hello/master
My question is; how can I get this output, thanks for helping.
master/yoda
use indexOf
String xStr = "hello/master/yoda";
String remv_last = xStr.substring(xStr.indexOf("/") + 1);
System.out.println(remv_last);
You can use simple indexOf it will give you the first occurrence only
String xStr = "hello/master/yoda";
String remv_last = xStr.substring(0, xStr.lastIndexOf("/"));
int firstIndex = xStr.indexOf("/");
String firstCharacter = xStr.substring(firstIndex,xStr.length());
System.out.println(remv_last);
System.out.println(firstCharacter);
It will print required
© 2022 - 2024 — McMap. All rights reserved.