Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there like "firstIndexOf" code?

Tags:

string

indexof

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
like image 243
Sertaç Avatar asked Sep 23 '17 13:09

Sertaç


1 Answers

use indexOf

String xStr = "hello/master/yoda";
String remv_last = xStr.substring(xStr.indexOf("/") + 1);
 System.out.println(remv_last);
like image 56
Pramod Yadav Avatar answered Oct 17 '22 05:10

Pramod Yadav