string - 有没有像 "firstIndexOf"这样的代码?

标签 string indexof

String xStr = "hello/master/yoda";
String remv_last = xStr.substring(0, xStr.lastIndexOf("/"))
System.out.println(remv_last);

输出
hello/master

我的问题是;我怎样才能得到这个输出,谢谢你的帮助。
master/yoda

最佳答案

使用 indexOf

String xStr = "hello/master/yoda";
String remv_last = xStr.substring(xStr.indexOf("/") + 1);
 System.out.println(remv_last);

关于string - 有没有像 "firstIndexOf"这样的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46380281/

相关文章:

javascript - 通过 "."识别 "if ... if"并且字符串中没有空格

go - panic :Golang 中的索引超出范围错误

javascript - indexOf 但对于对象呢?

python - 从数据提取中删除字母只留下数字Python

c++ - 如何在C++中转换为utf8字符串

c - 如果值相同,则将连续的项弹出堆栈

Android 资源 ID 分配不正确

javascript - 调用字符串时出错 :indexOf

c - 获取十六进制数字的字符表示(创建 char* 以显示十六进制值)

python - 使用 Python 在字符串列表中查找项目的索引